JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,537
- Office Version
- 365
- Platform
- Windows
I make use of a lot of named ranges so as to make my formulas more readable and more resistant to errors due to moving cells around. One of my favorite methods is to name entire columns and then use those names in formulas. Those formulas will then use the cells in the names ranges that are in the same row as the formulas. Here's a simple example. Column C has been assigned the name "A", column D has been assigned the name "B".
View attachment 4086
Column E combines the values in columns C & D using absolute addressing. Column G obtains the same result using the named ranges.
This works well for in-sheet formulas. It doesn't work nearly as well if I try to pass these named ranges to a UDF.
Column I passes the values to simple UDFs using absolute addressing. Here's the UDF code:
Column K tries it with the named ranges and gets a Value error.
I discovered a way to get around this design failure by performing an arithmetic operation on the named range parameters, which is pretty silly for the character values in rows 7 & 8.
Here's my question: Is there some code I can put in the UDFs so that they will work whether they are passed absolute addresses or named ranges?
PS: I hope I got the images right. The image inserting mechanism is a little flakey or maybe I just don;t know how to operate it.
View attachment 4086
Column E combines the values in columns C & D using absolute addressing. Column G obtains the same result using the named ranges.
This works well for in-sheet formulas. It doesn't work nearly as well if I try to pass these named ranges to a UDF.
Column I passes the values to simple UDFs using absolute addressing. Here's the UDF code:
VBA Code:
Function AddEm(V1, V2) As Double
AddEm = V1 + V2
End Function
Function JoinEm(V1, V2) As String
JoinEm = V1 & V2
End Function
Column K tries it with the named ranges and gets a Value error.
I discovered a way to get around this design failure by performing an arithmetic operation on the named range parameters, which is pretty silly for the character values in rows 7 & 8.
Here's my question: Is there some code I can put in the UDFs so that they will work whether they are passed absolute addresses or named ranges?
PS: I hope I got the images right. The image inserting mechanism is a little flakey or maybe I just don;t know how to operate it.