Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Rows in named range?

How can I determine (using VBA) how many rows and columns are in a named
range?


Many thanks.

--
Ian
--


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Rows in named range?

Use these...

Range("NamedRange").Rows.Count

Range("NamedRange").Columns.Count

changing my example "NamedRange" to your actual named range's name.

--
Rick (MVP - Excel)


"IanC" wrote in message ...
How can I determine (using VBA) how many rows and columns are in a named
range?


Many thanks.

--
Ian
--


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Rows in named range?

....and watch out for non-contiguous ranges.

Tim

"Rick Rothstein" wrote in message
...
Use these...

Range("NamedRange").Rows.Count

Range("NamedRange").Columns.Count

changing my example "NamedRange" to your actual named range's name.

--
Rick (MVP - Excel)


"IanC" wrote in message ...
How can I determine (using VBA) how many rows and columns are in a named
range?


Many thanks.

--
Ian
--


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Rows in named range?

Good point! These should work for both contiguous and non-contiguous
ranges...

Dim A As Range
......
For Each A In Range("NamedRange").Areas
TotalRows = TotalRows + A.Rows.Count
Next
For Each A In Range("NamedRange").Areas
TotalColumns = TotalColumns + A.Columns.Count
Next

Note, however, these return the total of the number of rows and/or columns
in each area for non-contiguous ranges, whether the row ranges and/or column
ranges overlap or not.

--
Rick (MVP - Excel)


"Tim Williams" wrote in message
...
...and watch out for non-contiguous ranges.

Tim

"Rick Rothstein" wrote in message
...
Use these...

Range("NamedRange").Rows.Count

Range("NamedRange").Columns.Count

changing my example "NamedRange" to your actual named range's name.

--
Rick (MVP - Excel)


"IanC" wrote in message
...
How can I determine (using VBA) how many rows and columns are in a named
range?


Many thanks.

--
Ian
--



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Rows in named range?

And if the OP wants total entire rows and total entire columns (these would
be the row and column ranges formed by the EntireRow and EntireColumn
properties of each cell in the NamedRange), he would need something like
this...

Dim A As Range, R As Range, C As Range
Dim TotalRows As Long, TotalColumns As Long
......
For Each A In Range("NamedRange").Areas
If R Is Nothing Then
Set R = A.EntireRow
Else
Set R = Union(R, A.EntireRow)
End If
If C Is Nothing Then
Set C = A.EntireColumn
Else
Set C = Union(C, A.EntireColumn)
End If
Next
For Each A In R.Areas
TotalRows = TotalRows + A.Rows.Count
Next
For Each A In C.Areas
TotalColumns = TotalColumns + A.Columns.Count
Next

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Good point! These should work for both contiguous and non-contiguous
ranges...

Dim A As Range
.....
For Each A In Range("NamedRange").Areas
TotalRows = TotalRows + A.Rows.Count
Next
For Each A In Range("NamedRange").Areas
TotalColumns = TotalColumns + A.Columns.Count
Next

Note, however, these return the total of the number of rows and/or columns
in each area for non-contiguous ranges, whether the row ranges and/or
column ranges overlap or not.

--
Rick (MVP - Excel)


"Tim Williams" wrote in message
...
...and watch out for non-contiguous ranges.

Tim

"Rick Rothstein" wrote in message
...
Use these...

Range("NamedRange").Rows.Count

Range("NamedRange").Columns.Count

changing my example "NamedRange" to your actual named range's name.

--
Rick (MVP - Excel)


"IanC" wrote in message
...
How can I determine (using VBA) how many rows and columns are in a
named range?


Many thanks.

--
Ian
--






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Rows in named range?

Thanks Rick. This is just what I needed. Unfortunately, I've met an
unexpected problem, but I'll put that in another post as it effectively
unrelated.

--
Ian
--

"Rick Rothstein" wrote in message
...
Use these...

Range("NamedRange").Rows.Count

Range("NamedRange").Columns.Count

changing my example "NamedRange" to your actual named range's name.

--
Rick (MVP - Excel)


"IanC" wrote in message ...
How can I determine (using VBA) how many rows and columns are in a named
range?


Many thanks.

--
Ian
--


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
UDF: Count rows in named range John[_141_] Excel Programming 9 January 7th 09 05:34 PM
How do I specify column for named range of rows hmm Charts and Charting in Excel 0 July 23rd 07 01:38 PM
Selecting multiple rows in a named range hdf Excel Programming 7 June 8th 07 11:05 AM
Deleting rows within a named range Barb Reinhardt Excel Programming 4 May 9th 07 07:39 PM
How to add rows(cells) to a named range Ctech[_12_] Excel Programming 4 October 6th 05 03:54 PM


All times are GMT +1. The time now is 01:10 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"