Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Counta with a range

I am trying to look at a range of cells to determine if the row is empty
within this range. But the code below is only looking at the first cell, not
the selected range.


Do

Empty_Check = Application.CountA(Cells(ActiveCell.Row,
1).Range("B1:N1").Select)
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select

Loop Until Empty_Check = 0

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Using Counta with a range

Here are two different approaches that work for me.

Approach #1 - cycle through the range and stop when finding first empty
cell
Sub StopAtEmpty()
For Each cell In Range("A1:A8")
If cell.Value = "" Then
MsgBox cell.Address & " is empty"
Exit Sub
End If
Next cell
End Sub

Approach #2 - cycle through the range and report status of each cell
Sub CheckEmpty()
For Each cell In Range("A1:A8")
If cell.Value = "" Then
MsgBox cell.Address & " is empty"
Else
MsgBox cell.Address & " is not empty"
End If
Next cell
End Sub


- John
www.johnmichl.com/exceltips.htm

Michael Whitney wrote:
I am trying to look at a range of cells to determine if the row is empty
within this range. But the code below is only looking at the first cell, not
the selected range.


Do

Empty_Check = Application.CountA(Cells(ActiveCell.Row,
1).Range("B1:N1").Select)
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select

Loop Until Empty_Check = 0


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Using Counta with a range

Hi Michael,

Very simillar but this will count the number of empty cell in any given range:


Sub Count_blank_in_range()
Dim c_cell As Range
Dim c_count As Integer
Set c_cell = Range("A1:A10")
For Each cell In c_cell
If cell = "" Then
c_count = c_count + 1
End If
Next cell
MsgBox (c_count)
End Sub

HTH

Simon

Michael Whitney wrote:
I am trying to look at a range of cells to determine if the row is empty
within this range. But the code below is only looking at the first cell, not
the selected range.

Do

Empty_Check = Application.CountA(Cells(ActiveCell.Row,
1).Range("B1:N1").Select)
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select

Loop Until Empty_Check = 0


--
--------------------
Simon - UK

Email at simon22mports [ a t ] hot mail [ d ot ]com

Message posted via http://www.officekb.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Counta with a range

Thanks - It looks like I will will have to use this method to check each cell
in the row and only stop my loop if the c_count variable stays at 0. I guess
the counta application command just does not work, correct?

"smw226 via OfficeKB.com" wrote:

Hi Michael,

Very simillar but this will count the number of empty cell in any given range:


Sub Count_blank_in_range()
Dim c_cell As Range
Dim c_count As Integer
Set c_cell = Range("A1:A10")
For Each cell In c_cell
If cell = "" Then
c_count = c_count + 1
End If
Next cell
MsgBox (c_count)
End Sub

HTH

Simon

Michael Whitney wrote:
I am trying to look at a range of cells to determine if the row is empty
within this range. But the code below is only looking at the first cell, not
the selected range.

Do

Empty_Check = Application.CountA(Cells(ActiveCell.Row,
1).Range("B1:N1").Select)
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select

Loop Until Empty_Check = 0


--
--------------------
Simon - UK

Email at simon22mports [ a t ] hot mail [ d ot ]com

Message posted via http://www.officekb.com


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Using Counta with a range

One way, using your existing code:

Do
Range("B" & ActiveCell.Row & _
":N" & ActiveCell.Row).Select
Empty_Check = _
Application.CountA(Range("B" & ActiveCell.Row & _
":N" & ActiveCell.Row))
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select
Loop Until Empty_Check = 0

Regards

Trevor


"Michael Whitney" <Michael wrote in
message ...
I am trying to look at a range of cells to determine if the row is empty
within this range. But the code below is only looking at the first cell,
not
the selected range.


Do

Empty_Check = Application.CountA(Cells(ActiveCell.Row,
1).Range("B1:N1").Select)
MsgBox (Str(Empty_Check))
ActiveCell.Offset(1, 0).Range("A1").Select

Loop Until Empty_Check = 0



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
CountA carlee Excel Discussion (Misc queries) 2 January 14th 10 10:28 AM
=sign(--counta(range)) not working righ t [email protected] Excel Worksheet Functions 4 July 29th 09 01:41 AM
using COUNTA DougMc Excel Discussion (Misc queries) 4 May 30th 05 12:57 AM
counta DanC Excel Worksheet Functions 4 January 5th 05 03:49 AM
COUNTA Function not working =COUNTA(C3:C69,"NH") MikeinNH Excel Worksheet Functions 2 November 8th 04 01:19 AM


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