Not entirely sure how to ask this:
I have a named range that I am using in a sub and will be using the same named range in a function.
Should I pass the named range as an argument to the function or just redefine the named range in the function?
I don't need to manipulate the named range immediately in the function - just need to use the named range in the function (see code snippet)
Vague question so I'll try to define some criteria with which to judge which is "better":
- Code readability
- Execution speed
- Security of code? (e.g. if you don't want people to be able to "see" your hidden code)
- Other criteria?
Option 1: Pass range as argument
Dim rRng as Range
Set rRng = Sheet3.Range ("aNamedRange")
Call TestFunction (rRng)
'Here's what the function "TestFunction" would look like
Function TestFunction (rRange as Range)
rRange (1,1) = "blah"
End Function
Option 2: Redefine range in function
Dim rRng as Range
Set rRng = Sheet3.Range ("aNamedRange")
Call TestFunction
'Here's what the function "TestFunction" would look like
Function TestFunction ()
Dim rRange as Range
Set rRange = Sheet3.Range ("aNamedRange")
rRange (1,1) = "blah"
End Function