I have a command button which calls two experimental (I.e. non-working) functions to try to get a named range given an index number. This should be simple but i get four empty cells for my pains. Can someone please spot the non-deliberate mistake. Ideally I'd like a function similar to either of the two that returns a range (object) that is referred to by a given name.
and the useless functions are...
Code:
Private Sub CommandButton6_Click()
Dim r As Range
Set r = GetRangeNameRefersToR(1)
[i5] = r.Address
[i6].Value = GetRangeNameRefersTo(2)
[i7].Value = GetRangeNameRefersTo(3)
[i8].Value = GetRangeNameRefersTo(4)
[i5:i8].Select
End Sub
and the useless functions are...
Code:
Function GetRangeNameRefersTo(TheIndex As Long) As String
Dim S As String
On Error Resume Next
S = Names(TheIndex).RefersToRange.Address
End Function
Function GetRangeNameRefersToR(TheIndex As Long) As Variant
Dim r As Variant
On Error Resume Next
r = Names(TheIndex).RefersToRange
Set GetRangeNameRefersToR = r
End Function