I have created a .xlam file with a tab named 'Tables' in the spreadsheet that contains named ranges that are passed into the various UDFs that I have created. If the value passed into the function through 'Table' or 'Table2' does not point to a valid named range the function returns the #VALUE! error and gets hung up on the line below assigning a range to 'RANGE_1' or 'RANGE_2'. In this case I would like the function to indicate which named range it has a problem with. How do I test to make sure the named ranges are valid?
Code:
Function test_function(Number, Optional Table As String = "missing", _
Optional Table2 As String = "missing")
.
.
.
If Table <> "missing" Then
RANGE_1 = ThisWorkbook.Sheets("Tables").Range(Table).Value
End If
If Table2 <> "missing" Then
RANGE_2 = ThisWorkbook.Sheets("Tables").Range(Table2).Value
End If
.
.
.
End Function