Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help with counting cells in a selected range


I have a situation here.
1.) I need to select a range of cells,
2.) count the number of cells in the range that contains values and also
3.) count the number of cells in the range that have a RED fill

How do I accomplish this? This is what I have so far:
marketWS.Range("D6:BG" & marketCurrRow - 1).Select
With Selection
cnt = .Cells.Count
End With
marketWS.Range("M1") = cnt

But cnt is counting all the cells in the range("D6:BG" & marketCurrRow - 1)
but I only want to count the cells that have values in them. Any ideas?
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Help with counting cells in a selected range

--Use Worksheet function CountA() as below
Dim rngTemp As Range

Set rngTemp = MARKETWS.Range("D6:BG" & marketcurrrow - 1)
cnt = WorksheetFunction.CountA(rngTemp)
MARKETWS.Range("M1") = cnt

--One way to get the number of red filled cells

For Each cell In rngTemp
If cell.Interior.ColorIndex = 3 Then _
redcount = redcount + 1
Next

If this post helps click Yes
---------------
Jacob Skaria


"Ayo" wrote:


I have a situation here.
1.) I need to select a range of cells,
2.) count the number of cells in the range that contains values and also
3.) count the number of cells in the range that have a RED fill

How do I accomplish this? This is what I have so far:
marketWS.Range("D6:BG" & marketCurrRow - 1).Select
With Selection
cnt = .Cells.Count
End With
marketWS.Range("M1") = cnt

But cnt is counting all the cells in the range("D6:BG" & marketCurrRow - 1)
but I only want to count the cells that have values in them. Any ideas?
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Help with counting cells in a selected range

Since in any case you have a loop you can check for nonblank cells within the
loop or use COUNTA()

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

--Use Worksheet function CountA() as below
Dim rngTemp As Range

Set rngTemp = MARKETWS.Range("D6:BG" & marketcurrrow - 1)
cnt = WorksheetFunction.CountA(rngTemp)
MARKETWS.Range("M1") = cnt

--One way to get the number of red filled cells

For Each cell In rngTemp
If cell.Interior.ColorIndex = 3 Then _
redcount = redcount + 1
Next

If this post helps click Yes
---------------
Jacob Skaria


"Ayo" wrote:


I have a situation here.
1.) I need to select a range of cells,
2.) count the number of cells in the range that contains values and also
3.) count the number of cells in the range that have a RED fill

How do I accomplish this? This is what I have so far:
marketWS.Range("D6:BG" & marketCurrRow - 1).Select
With Selection
cnt = .Cells.Count
End With
marketWS.Range("M1") = cnt

But cnt is counting all the cells in the range("D6:BG" & marketCurrRow - 1)
but I only want to count the cells that have values in them. Any ideas?
Thanks.

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
counting spercific charaters in selected cells Tom5 Excel Programming 1 June 9th 08 03:33 PM
How do I set a range to the currently selected cells? [email protected] Excel Programming 2 January 4th 08 11:54 AM
Set Range Using Selected Cells Paputxi Excel Programming 3 May 2nd 06 06:32 PM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
max/min of a selected range of cells Srikanth Ganesan[_2_] Excel Programming 1 September 1st 04 10:31 PM


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