Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default count cells in range

Hello,

I’ve thought about this one for a while, but haven’t been able to
reason out why. Haven’t found anything in the groups that quite
addresses this. Hopefully someone can straighten me out.

Set r = Range("A1:C3")
r.Count returns number of cells (9)

Set r2 = Intersect(r, Rows(1))
r2.Count returns number of cells (3)

but

Set r2 = r.Rows(1)
Now, r2.Count returns number of rows (1)

I now have to specify cells to get the cell count
r2.Cells.Count returns number of cells (3)

Thanks for your help,

regards,

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default count cells in range

All that is returned for this:

Set r2 = r.Rows(1)

is the row, not the cells.


"Dave Unger" wrote:

Hello,

Ive thought about this one for a while, but havent been able to
reason out why. Havent found anything in the groups that quite
addresses this. Hopefully someone can straighten me out.

Set r = Range("A1:C3")
r.Count returns number of cells (9)

Set r2 = Intersect(r, Rows(1))
r2.Count returns number of cells (3)

but

Set r2 = r.Rows(1)
Now, r2.Count returns number of rows (1)

I now have to specify cells to get the cell count
r2.Cells.Count returns number of cells (3)

Thanks for your help,

regards,

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default count cells in range

Hi JLGWhiz,

All that is returned for this:

Set r2 = r.Rows(1)

is the row, not the cells.


So why isn't Set r2 = Intersect(r, Rows(1)) the same? I'm missing a
subtle difference here.

Thanks for your reply,

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default count cells in range

Hi JLGWhiz,

All that is returned for this:

Set r2 = r.Rows(1)

is the row, not the cells.


So why isn't Set r2 = Intersect(r, Rows(1)) the same? I'm missing a
subtle difference here.

Thanks for your reply,

Dave


I see - probably (and I'm guessing here!) because it's the intersection of a
range of *cells* with a range of a row, and therefore Count produces the
Count of the smallest unit, i.e. cells.

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

The intersection of a square of cells... Range("A1:C3")... and an entire
row... Rows(1)... is only the range of cells they have in common...
Range("A1:C1"). When you ask for a count of that intersection, you are
asking the same thing as Range("A1:C1").Count

--
Rick (MVP - Excel)


"Dave Unger" wrote in message
...
Hi JLGWhiz,

All that is returned for this:

Set r2 = r.Rows(1)

is the row, not the cells.


So why isn't Set r2 = Intersect(r, Rows(1)) the same? I'm missing a
subtle difference here.

Thanks for your reply,

Dave




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default count cells in range

Just to be clear about this... Rows(1) is the same as Range("A1:IV1") for
versions of Excel prior to XL2007 and Range("A1:XFD1") for XL2007. So the
Intersect function is finding the range of cells in common between
Range("A1:C3") and, for say XL2003, Range("A1:IV1"). That intersection is
the three-cell range Range("A1:C1"), whose Count property is 3.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
The intersection of a square of cells... Range("A1:C3")... and an entire
row... Rows(1)... is only the range of cells they have in common...
Range("A1:C1"). When you ask for a count of that intersection, you are
asking the same thing as Range("A1:C1").Count

--
Rick (MVP - Excel)


"Dave Unger" wrote in message
...
Hi JLGWhiz,

All that is returned for this:

Set r2 = r.Rows(1)

is the row, not the cells.


So why isn't Set r2 = Intersect(r, Rows(1)) the same? I'm missing a
subtle difference here.

Thanks for your reply,

Dave



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default count cells in range

Hi Rick,


On Sep 16, 1:57*am, "Rick Rothstein"
wrote:
Just to be clear about this... Rows(1) is the same as Range("A1:IV1") for
versions of Excel prior to XL2007 and Range("A1:XFD1") for XL2007. So the
Intersect function is finding the range of cells in common between
Range("A1:C3") and, for say XL2003, Range("A1:IV1"). That intersection is
the three-cell range Range("A1:C1"), whose Count property is 3.


Thanks for your reply. Either I'm missing your point, or you're
missing mine.

Set r=range("A1:C3")

Set r2 = r.Rows(1)

The address of r2 is A1:C1, and I would expect r2.Count to return 3,
but it doesn't - it returns 1

regards,

Dave.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default count cells in range

Sometimes, Excel will guess wrong. If your range is an entirerow or an entire
column, it'll use (always???) use the number of rows or columns.

If you don't want excel to guess, be specific.

msgbox r.cells.count
msgbox r.columns.count
msgbox r.rows.count
msgbox r.areas.count
....

As a corollary, you may want to change things like:
dim myCell as range
dim myRng as range
set myrng = something
for each mycell in myrng
to:
for each mycell in myrng.cells
(or .columns or .rows or .areas or whatever you need)

Dave Unger wrote:

Hello,

I’ve thought about this one for a while, but haven’t been able to
reason out why. Haven’t found anything in the groups that quite
addresses this. Hopefully someone can straighten me out.

Set r = Range("A1:C3")
r.Count returns number of cells (9)

Set r2 = Intersect(r, Rows(1))
r2.Count returns number of cells (3)

but

Set r2 = r.Rows(1)
Now, r2.Count returns number of rows (1)

I now have to specify cells to get the cell count
r2.Cells.Count returns number of cells (3)

Thanks for your help,

regards,

Dave


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default count cells in range

Hi Dave,

That is the route I've been following (being specific), as I've
encountered this scenario a number of times. Thanks for your insight
on this.

regards,

Dave (Unger)


On Sep 16, 5:51*am, Dave Peterson wrote:
Sometimes, Excel will guess wrong. *If your range is an entirerow or an entire
column, it'll use (always???) use the number of rows or columns.

If you don't want excel to guess, be specific.

msgbox r.cells.count
msgbox r.columns.count
msgbox r.rows.count
msgbox r.areas.count
...

As a corollary, you may want to change things like:
dim myCell as range
dim myRng as range
set myrng = something
for each mycell in myrng
to:
for each mycell in myrng.cells
(or .columns or .rows or .areas or whatever you need)

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 how many different cells are in a range John T Kennedy[_2_] Excel Discussion (Misc queries) 1 June 25th 09 06:22 PM
Count a range of cells using an IF Access Joe Excel Worksheet Functions 9 July 31st 08 12:26 AM
Count Empty Cells in Range After Cells with Data David Excel Programming 16 September 17th 06 03:03 PM
Count Cells in Range Steve C Excel Programming 3 February 28th 06 02:15 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM


All times are GMT +1. The time now is 11:46 PM.

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"