Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Define name, count rows problem.

I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the €śdata€ť range. The following code yields
10 rows and not the expected 21. It appears the code only considers the first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range(€śdata€ť)
NumberOfRows = CheckArea.Rows.Count

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Define name, count rows problem.

Hi,

If all areas are below each other or on separate sets of rows (ie, no rows
in common),
eg: { B1:G10, C15:F20, Z30:AB50 } ,
but not { B1:G10, Z5:BA50} where rows 5:10 appear in both areas
then

Dim r as range, ttl as long
Set CheckArea = Range(€śdata€ť)
For Each r in CheckAreas.Areas
ttl=ttl+r.rows.count
Next
Msgbox ttl

- In all cases, you should be able to do (using loop through all rows):

Dim r as range, rResult as range
Set CheckArea = Range(€śdata€ť)
Set rResult=checkarea.rows(1)

'Create range of unique entire rows
For Each r in CheckAreas.Rows
set rResult=Application.union(rResult,r.entirerow)
Next

'Count rows for each range
For Each r in rResult.Areas
ttl=ttl+r.rows.count
Next
Msgbox ttl

--
Regards,
SĂ©bastien


"sommer" wrote:

I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the €śdata€ť range. The following code yields
10 rows and not the expected 21. It appears the code only considers the first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range(€śdata€ť)
NumberOfRows = CheckArea.Rows.Count

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Define name, count rows problem.

Hi Sommer,

Based on a suugestion by Dana DeLouis, try:

Sub Tester03()

Dim i As Long

i = Intersect(Range("Data").EntireRow, _
Columns(1)).Cells.Count

MsgBox i

End Sub


---
Regards,
Norman



"sommer" wrote in message
...
I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the
Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the "data" range. The following code
yields
10 rows and not the expected 21. It appears the code only considers the
first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range("data")
NumberOfRows = CheckArea.Rows.Count



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Define name, count rows problem.

nice, much simpler :-)
--
Regards,
SĂ©bastien


"Norman Jones" wrote:

Hi Sommer,

Based on a suugestion by Dana DeLouis, try:

Sub Tester03()

Dim i As Long

i = Intersect(Range("Data").EntireRow, _
Columns(1)).Cells.Count

MsgBox i

End Sub


---
Regards,
Norman



"sommer" wrote in message
...
I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the
Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the "data" range. The following code
yields
10 rows and not the expected 21. It appears the code only considers the
first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range("data")
NumberOfRows = CheckArea.Rows.Count




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Define name, count rows problem.

Hi Sommer,

To add,

It appears the code only considers the first
part of the named range and not the entire string.


See 'Areas Collection Object' in VBA help. See particularly the comments
immediately preceding the help example.

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Sommer,

Based on a suugestion by Dana DeLouis, try:

Sub Tester03()

Dim i As Long

i = Intersect(Range("Data").EntireRow, _
Columns(1)).Cells.Count

MsgBox i

End Sub


---
Regards,
Norman



"sommer" wrote in message
...
I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the
Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the "data" range. The following code
yields
10 rows and not the expected 21. It appears the code only considers the
first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range("data")
NumberOfRows = CheckArea.Rows.Count







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Define name, count rows problem.

Norman
Thanks for your help, problem solved.

"Norman Jones" wrote:

Hi Sommer,

To add,

It appears the code only considers the first
part of the named range and not the entire string.


See 'Areas Collection Object' in VBA help. See particularly the comments
immediately preceding the help example.

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Sommer,

Based on a suugestion by Dana DeLouis, try:

Sub Tester03()

Dim i As Long

i = Intersect(Range("Data").EntireRow, _
Columns(1)).Cells.Count

MsgBox i

End Sub


---
Regards,
Norman



"sommer" wrote in message
...
I would like to count the number of rows in a named range that contains
multiple areas on the same worksheet. To setup the range, I held the
Control
key down while selecting the three different areas and then selected
InsertNameDefine to establish the "data" range. The following code
yields
10 rows and not the expected 21. It appears the code only considers the
first
part of the named range and not the entire string.
Any help would be appreciated.
Thanks
Sommer

Names in workbook:
data

Refers to:
=Sheet1!$A$3:$M$12,Sheet1!$A$25:$M$30,Sheet1!$A$40 :$M$44

Macro code:
Set CheckArea = Range("data")
NumberOfRows = CheckArea.Rows.Count






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
pivot table - Can I pre-define rows and columns? WRBailey Excel Discussion (Misc queries) 3 May 17th 05 06:11 PM
problem with Rows.Count and comparing cells PZipko Excel Programming 3 July 9th 04 07:33 PM
Problem with UsedRange.Rows.Count alainB[_15_] Excel Programming 4 April 29th 04 10:29 PM
problem using Set statement to define range object mel Excel Programming 0 February 4th 04 06:10 PM
Define Range in Deleting Empty Rows HamishM[_3_] Excel Programming 1 December 19th 03 01:17 AM


All times are GMT +1. The time now is 08:45 AM.

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

About Us

"It's about Microsoft Excel"