"If column is empty" not working

E

Ed

In a macro, I insert a formula into a column and copy down to the bottom of
the range. The formula is basically "IF there's an error, THEN insert this,
ELSE "" ". I'm trying to detect if the column was empty - ie: the formula
returns "" - but it's not working. I guess what I'm using is detecting a
formula in the cell, so it's not empty? Any suggestions are welcome.

Here's what I've got:

' If there are no TIRs without naratives
If Application.CountA(Range("AM2:AM12000")) = 0 Then

' Run this macro
InsertNarrLinks

Else
' Toggles on AutoFilter
Range("AM1").Select
Selection.AutoFilter

End If


Ed
 
P

papou

Ed
Using CountA will not return 0 since formulas are in your range of cells.
Try
If Application.Sum(Range("AM2:AM12000")) = 0
This will return 0 if you have no values in your range
HTH
Regards
Pascal

Ed said:
But the cell is supposed to have a formula. It is:
=IF(COUNTIF(TIRs!$AL$2:$AL$12000,Sheet1!C2)=0,Sheet1!C2,"")

I want to detect if the formula has returned "" in all cells, meaning they
are all blank. If so, then run the other macro. Else activate the
AutoFilter. It keeps activating the AutoFilter, meaning it doesn't see the
cells as blank, even though there is no value in them and the AutoFilter has
nothing for me to select.

Ed


Don Guillett said:
try
If [am2:am12000].HasFormula = False Then

Ed said:
In a macro, I insert a formula into a column and copy down to the
bottom
of
the range. The formula is basically "IF there's an error, THEN insert this,
ELSE "" ". I'm trying to detect if the column was empty - ie: the formula
returns "" - but it's not working. I guess what I'm using is
detecting
 
E

Ed

Thank you, Papou. It will be next Tuesday before I get a chance to try
this - I'll let you how it worked.

Ed

papou said:
Ed
Using CountA will not return 0 since formulas are in your range of cells.
Try
If Application.Sum(Range("AM2:AM12000")) = 0
This will return 0 if you have no values in your range
HTH
Regards
Pascal

Ed said:
But the cell is supposed to have a formula. It is:
=IF(COUNTIF(TIRs!$AL$2:$AL$12000,Sheet1!C2)=0,Sheet1!C2,"")

I want to detect if the formula has returned "" in all cells, meaning they
are all blank. If so, then run the other macro. Else activate the
AutoFilter. It keeps activating the AutoFilter, meaning it doesn't see the
cells as blank, even though there is no value in them and the AutoFilter has
nothing for me to select.

Ed


Don Guillett said:
try
If [am2:am12000].HasFormula = False Then

In a macro, I insert a formula into a column and copy down to the bottom
of
the range. The formula is basically "IF there's an error, THEN insert
this,
ELSE "" ". I'm trying to detect if the column was empty - ie: the formula
returns "" - but it's not working. I guess what I'm using is
detecting
a
formula in the cell, so it's not empty? Any suggestions are welcome.

Here's what I've got:

' If there are no TIRs without naratives
If Application.CountA(Range("AM2:AM12000")) = 0 Then

' Run this macro
InsertNarrLinks

Else
' Toggles on AutoFilter
Range("AM1").Select
Selection.AutoFilter

End If


Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top