Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Counting cells with data in them

dim myRng as range
with activesheet
set myrng = .range("d1",.range("d1").end(xldown))
end with

msgbox application.counta(myrng)


This'll count everything--including formulas that evaluate to "".


Tony wrote:

Sorry if this post came up twice. I would like to know how to do a count
function on a selection of cells. My sheet has been filtered on this column
and then the following lines are used.

Range("d1").Select
Range(Selection, Selection.End(xlDown)).Select
sectornum = Selection.Count

This selects all the cells down to the last cell that has data in it but
then the variable is set to the total amount of cells selected. All I want to
know is how many cells have something in them. Thank you!


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Counting cells with data in them

Good idea! I'd forgotten about CountA. But you need to use

Set myRng = .Range("D1", .Range("D65536").End(xlUp))

because

Set myRng = .Range("d1", .Range("d1").End(xlDown))

will stop at the first empty cell in Column D. I just tried it.

Regards,
Wes
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Counting cells with data in them

True, but this apparently isn't an issue for the original poster:

Range(Selection, Selection.End(xlDown)).Select
This selects all the cells down to the last cell that has data in it but


I would guess that Dave tried it several years ago and is aware of the
difference.

--
Regards,
Tom Ogilvy


"SunTzuComm" wrote in message
...
Good idea! I'd forgotten about CountA. But you need to use

Set myRng = .Range("D1", .Range("D65536").End(xlUp))

because

Set myRng = .Range("d1", .Range("d1").End(xlDown))

will stop at the first empty cell in Column D. I just tried it.

Regards,
Wes



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Counting cells with data in them

In fact, I changed my post to match the OP. 'Cause sometimes there's a reason
the OP used their code. <vbg.

Tom Ogilvy wrote:

True, but this apparently isn't an issue for the original poster:

Range(Selection, Selection.End(xlDown)).Select
This selects all the cells down to the last cell that has data in it but


I would guess that Dave tried it several years ago and is aware of the
difference.

--
Regards,
Tom Ogilvy

"SunTzuComm" wrote in message
...
Good idea! I'd forgotten about CountA. But you need to use

Set myRng = .Range("D1", .Range("D65536").End(xlUp))

because

Set myRng = .Range("d1", .Range("d1").End(xlDown))

will stop at the first empty cell in Column D. I just tried it.

Regards,
Wes


--

Dave Peterson

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
COUNTIF, only counting once if both cells contain the data Navy Luke Excel Worksheet Functions 5 December 2nd 08 10:26 PM
Counting Cells with same data pulling my hair out Excel Discussion (Misc queries) 3 November 21st 07 07:21 AM
Counting cells that contain data Karl Excel Discussion (Misc queries) 2 October 14th 06 07:18 PM
Counting cells with data jimbob Excel Discussion (Misc queries) 3 November 26th 05 11:00 PM
Counting cells with data in them SunTzuComm Excel Programming 0 September 18th 04 12:59 AM


All times are GMT +1. The time now is 05:59 PM.

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"