Posted by yogesh k. potdar on October 18, 2001 5:48 AM
How do I put a condition statement in a macro to detect blank cells
I tried:
for j=1 to 5
test = Cells(j, 6).Value
if test <> "" Then
.....
Endif
Next
I expect it to not enter If loop for all j's where
6th column is blank. But this does not happen..
Posted by Juan Pablo on October 18, 2001 6:40 AM
Try
for j=1 to 5
If Not IsEmpty(Cells(j, 6)) <> "" Then
.....
Endif
Next
Juan Pablo
Posted by yogesh k. potdar on October 18, 2001 6:53 AM
The suggestion give "Type Mismatch" error ? Any thoughts??? Try
Posted by Aladin Akyurek on October 18, 2001 6:59 AM
Juan,
Why not use an equivalent of =LEN(A1)>0?
Aladin
Posted by Juan Pablo on October 18, 2001 7:11 AM
I think you could use it, but anyway, i forgot to erase the <> "" part. It should read
If Not IsBlank(Cells(j, 6)) then
I guess using
If Len(Cells(j, 6))> 0 then
should work as well. I like the first one because it's "easier" to understand when you're debugging...
Juan Pablo Juan, Why not use an equivalent of =LEN(A1)>0? Aladin
Posted by Jonathan on October 18, 2001 7:36 AM
Here's a slightly different approach
If Application.WorksheetFunction.CountBlank(ActiveCell) = 0 Then
MsgBox "Cell not blank"
Else
MsgBox "Cell is Blank"
End If
The suggestion give "Type Mismatch" error ? Any thoughts??? : Try : for j=1 to 5
Posted by Aladin Akyurek on October 18, 2001 7:41 AM
If Not IsBlank(Cells(j, 6)) then I guess using If Len(Cells(j, 6))> 0 then should work as well. I like the first one because it's "easier" to understand when you're debugging...
I didn't suggest it in order to help you out. There is no need for that. I knew you'd use the equivalent of ISBLANK. Because of that ephemeral problem of blank vs empty, I thought you might be interested in using of the VBA equivalent of LEN...
Aladin
Posted by Juan Pablo on October 18, 2001 7:49 AM
I know you were, it's cleaner, faster, but a little more "difficult"... thanks (NT)
Posted by yogesh k. potdar on October 18, 2001 10:35 AM
Re: Len worked where ISEmpty didnot :)
My Excel file does not seem to recognize "Empty"
cells correctly, its origianally imported from a test editor..And Excel'97 - that I use - does not
recognize ISBlank..I don't know WHY???
anyway.. LEN thing worked fine.. and I was able to use it in a couple of other palces as well..
thanks,
-Yogesh
Posted by Juan Pablo on October 18, 2001 1:09 PM
Re: Len worked where ISEmpty didnot :)
Don't know what am i thinking... it's not IsBlank, it should work with IsEmpty... but if you imported them from a text editor maybe excel doesn't recognize the cell as "empty".
Juan Pablo My Excel file does not seem to recognize "Empty"