I am working on a macro which will require referencing a large number of named ranges using:
ThisWorkbook.Names("$NAMEDRANGE$").RefersToRange.$METHOD$
I thought it might make the code easier to read/work with if I could create a function which I could use as follows:
NamedRange("$NAMEDRANGE$").$METHOD$
Without really knowing if it would work, I tried the following:
Function NamedRange(ByVal sName As String) As Object
return ThisWorkbook.Names(sName).RefersToRange
End Function
This won't even compile, producing an
Expected: end of statement
I think I may need to use a Class Module, but I'm not very familiar with them. Is this possible, or should I just spell out the entire reference on each line?
I have been spending too much time in C. This code works perfectly:
Function NamedRange(ByVal sName As String) As Object
Set NamedRange = ThisWorkbook.Names(sName).RefersToRange
End Function
Thanks for the help!