UDF: Count rows in named range
If you want to pass the name of the range, one way:
Public Function RowsInNamedRange(ByVal sName As String) As Long
On Error Resume Next
RowsInNamedRange = _
ActiveWorkbook.Names(sName).RefersToRange.Rows.Cou nt
End Function
In article
,
John wrote:
I'm not a VBA expert, and this is a very simple function...
I'm trying to create a function that will count the number of rows in
a named range. The function will be used in a formula in the workbook.
This is what I have:
-------------------------------
Function RowsInNamedRange(NamedRange As Range) As Integer
RowsInNamedRange = Range(NamedRange).Rows.Count
End Function
-------------------------------
When I test via immediate window using:
? RowsInNamedRange "rngNamedRange1"
Where "rngNamedRange1" is a named range. I get a type mismatch error.
I know this is a simple fix...but just haven't figured it out yet. Any
pointers??
|