jjefferson
Technical User
I've been banging my head against this simple thing, tried suggested approaches found in searches without success, and need to ask for assistance.
I have three named ranges on a sheet, each referring to a single cell. Three buttons each call their own unique sub in the module.
I would like each of those button-subs to be able to call a generic sub in the module, passing the range or range name (whatever works) as an argument. That generic sub would update the value in the range that was passed to it.
I have tried passing the range name as a string, and also as a range object, but end up getting various errors, mostly "Method 'Range' of Object '_Global' failed".
I have tried (all abbreviated but is illustrative):
I have also tried:
Still very new to the VBA world and the Excel object model so I'm certain (hope) that I am missing something very basic and simple. I'd like Sub2 and Sub3 to also be able to call GenSub passing a different named range to be updated.
Thanks for a gentle shove in the right direction!
I have three named ranges on a sheet, each referring to a single cell. Three buttons each call their own unique sub in the module.
I would like each of those button-subs to be able to call a generic sub in the module, passing the range or range name (whatever works) as an argument. That generic sub would update the value in the range that was passed to it.
I have tried passing the range name as a string, and also as a range object, but end up getting various errors, mostly "Method 'Range' of Object '_Global' failed".
I have tried (all abbreviated but is illustrative):
Code:
Sub Sub1()
Dim strNR as String
strNR = "NamedRange1"
Call GenSub(strNR)
End Sub
Sub GenSub(strRangeName as String)
...some stuff goes on...
Range(strRangeName).Value = "Something"
End Sub
I have also tried:
Code:
Sub Sub1()
Dim rngRN as Range
Set rngRN = Range("NamedRange1") <-- usually errors here
Call GenSub(rngRN)
End Sub
Sub GenSub(rngRangeObj as Range)
...more stuff...
rngRangeObj.Value = "Something"
End Sub
Still very new to the VBA world and the Excel object model so I'm certain (hope) that I am missing something very basic and simple. I'd like Sub2 and Sub3 to also be able to call GenSub passing a different named range to be updated.
Thanks for a gentle shove in the right direction!