I need to determine the number of rows in a named range. I have developed the following function to do the task; but suspect that Mr Gates and Co. have probably provided a much more efficient solution.
Can anyone point me in the right direction?
Public Function RangeRows(myRange) Dim myLocn As String Dim myTop As Long Dim myBottom As Long Dim i As Long ' Returns a string in the form of: ='MY WORKSHEET'!R2C1:R7C1 myLocn = ActiveWorkbook.Names(myRange).RefersToR1C1 ' Locate first "R" following first "!". ' The number of the top row starts on the next character. myTop = InStr(1, myLocn, "!") myTop = InStr(myTop, myLocn, "R") + 1 ' Locate next "C". The number of the top row ends there. i = InStr(myTop, myLocn, "C") ' Define the top row of the range. myTop = Val(Mid(myLocn, myTop, i - myTop)) ' Locate next "R" . The number of the bottom row starts on ' the next character. myBottom = InStr(i, myLocn, "R") + 1 ' Locate next "C". The number of the bottom row ends there. i = InStr(myBottom, myLocn, "C") ' Define the bottom row of the range. myBottom = Val(Mid(myLocn, myBottom, i - myBottom)) RangeRows = myBottom - myTop + 1 End Function