Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default UDF: Count rows in named range




Since NamedRange is already a range, you don't need to wrap it up in a
Range object. E.g., use


RowsInNameRange=NameRandge.Rows.Count

If, however, you wanted to pass the name of a range as a string, use

Function RowsInNamedRange(NamedRange As String) As Long
RowsInNamedRange=Range(NamedRange).Rows.Count
End Function

Since the number of rows in a worksheet is greater than the number
that can be stored in an Integer type variable, you should use As Long
instead of As Integer.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

On Tue, 6 Jan 2009 12:52:15 -0800 (PST), 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??

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count(if(... using array formula: can I use a named range in my ca katy Excel Worksheet Functions 1 January 15th 08 02:13 AM
How to count number of pages in a named range rm81 Excel Programming 2 June 9th 06 05:49 PM
How do I count a named range for a specific word or acronym? brandyb Excel Worksheet Functions 1 November 4th 05 07:50 PM
Count formula within a named range. PW11111 Excel Discussion (Misc queries) 2 July 19th 05 09:29 AM
Dynamic Named Range count Matt Jensen Excel Programming 5 December 14th 04 01:04 PM


All times are GMT +1. The time now is 11:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"