Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 194
Default IF entire range blank THEN ...

I end a macro by enableing the AutoFilter so I can stop and check for my
ERROR message. If there is no cell with my error value, then I proceed to
the next step. It has just dawned on me that I can probably code this so
that
IF there is no value in any cell in B2:B700 THEN do this ELSE exit sub

I tried writing
' B2:B7000 is my range; C2 is an empty cell
IF (COUNTIF($B$2:$B$7000,C2)=0 THEN
' next routine
ELSE Exit Sub

but it keeps telling me $ is an invalid character. What am I missing?

Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default IF entire range blank THEN ...

The syntax would be:
IF Application.COUNTIf(Range("B2:B700"),Range("C2"))= 0 THEN
' next routine
ELSE
Exit Sub
End if

but I would use CountA

IF Application.COUNTA(Range("B2:B700"))=0 THEN
' next routine
ELSE
Exit Sub
End if

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
I end a macro by enableing the AutoFilter so I can stop and check for my
ERROR message. If there is no cell with my error value, then I proceed to
the next step. It has just dawned on me that I can probably code this so
that
IF there is no value in any cell in B2:B700 THEN do this ELSE exit sub

I tried writing
' B2:B7000 is my range; C2 is an empty cell
IF (COUNTIF($B$2:$B$7000,C2)=0 THEN
' next routine
ELSE Exit Sub

but it keeps telling me $ is an invalid character. What am I missing?

Ed




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 194
Default IF entire range blank THEN ...

Thank you, Tom. It works great!

As for the $ as an invalid character, is that just the dirfference between
writing a formula, and writing VBA? In other words, I shouldn't assume that
just because a formula in a worksheet is good, that's what VBA will
recognize in the same way?

Ed


"Tom Ogilvy" wrote in message
...
The syntax would be:
IF Application.COUNTIf(Range("B2:B700"),Range("C2"))= 0 THEN
' next routine
ELSE
Exit Sub
End if

but I would use CountA

IF Application.COUNTA(Range("B2:B700"))=0 THEN
' next routine
ELSE
Exit Sub
End if

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
I end a macro by enableing the AutoFilter so I can stop and check for my
ERROR message. If there is no cell with my error value, then I proceed

to
the next step. It has just dawned on me that I can probably code this

so
that
IF there is no value in any cell in B2:B700 THEN do this ELSE exit sub

I tried writing
' B2:B7000 is my range; C2 is an empty cell
IF (COUNTIF($B$2:$B$7000,C2)=0 THEN
' next routine
ELSE Exit Sub

but it keeps telling me $ is an invalid character. What am I missing?

Ed






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default IF entire range blank THEN ...

In VBA, you need to pass a range object when a range is need in a formula.
In a worksheet, the functions understand A1:B9 refers to a range - in VBA
you have to use a range object.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
Thank you, Tom. It works great!

As for the $ as an invalid character, is that just the dirfference between
writing a formula, and writing VBA? In other words, I shouldn't assume

that
just because a formula in a worksheet is good, that's what VBA will
recognize in the same way?

Ed


"Tom Ogilvy" wrote in message
...
The syntax would be:
IF Application.COUNTIf(Range("B2:B700"),Range("C2"))= 0 THEN
' next routine
ELSE
Exit Sub
End if

but I would use CountA

IF Application.COUNTA(Range("B2:B700"))=0 THEN
' next routine
ELSE
Exit Sub
End if

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
I end a macro by enableing the AutoFilter so I can stop and check for

my
ERROR message. If there is no cell with my error value, then I

proceed
to
the next step. It has just dawned on me that I can probably code this

so
that
IF there is no value in any cell in B2:B700 THEN do this ELSE exit sub

I tried writing
' B2:B7000 is my range; C2 is an empty cell
IF (COUNTIF($B$2:$B$7000,C2)=0 THEN
' next routine
ELSE Exit Sub

but it keeps telling me $ is an invalid character. What am I missing?

Ed








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 194
Default IF entire range blank THEN ...

Thanks, Tom. I appreciate the info.

Ed


"Tom Ogilvy" wrote in message
...
In VBA, you need to pass a range object when a range is need in a formula.
In a worksheet, the functions understand A1:B9 refers to a range - in VBA
you have to use a range object.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
Thank you, Tom. It works great!

As for the $ as an invalid character, is that just the dirfference

between
writing a formula, and writing VBA? In other words, I shouldn't assume

that
just because a formula in a worksheet is good, that's what VBA will
recognize in the same way?

Ed

<SNIP
I tried writing
' B2:B7000 is my range; C2 is an empty cell
IF (COUNTIF($B$2:$B$7000,C2)=0 THEN
' next routine
ELSE Exit Sub

but it keeps telling me $ is an invalid character. What am I

missing?





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
Average Formula to display blank cell if named range is blank Rachael F Excel Worksheet Functions 3 February 22nd 08 05:05 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
How can you add a blank row, per every other row, on an entire Laura Excel Discussion (Misc queries) 2 June 30th 06 01:01 AM
Easiest way to delete blank cells in column (not entire row) sramsey Excel Discussion (Misc queries) 4 February 16th 06 04:28 PM
remove blank lines from an entire spreadsheet mdeanda Excel Worksheet Functions 2 April 21st 05 01:53 PM


All times are GMT +1. The time now is 02:53 AM.

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"