cells with null or no data

R

Rpettis31

I have code that I have tried in various ways yet I can not get the code to
recognize a blank cell.
For z1 = 7 To 1300
If Cells(z1, 9) = "" Then Cells(z1, 10) = "HI"
If IsNull(Cells(z1, 9)) = True Then Cells(z1, 10) = "HI"
Next z1

I only used the word hi to stick out on the sheet.
 
P

Per Jessen

Are you sure the cells are empty. A cell may be "false empty" if it contains
a space character.

Try this:

For z1 = 7 To 1300
If Trim(Cells(z1, 9)) = "" Then Cells(z1, 10) = "HI"
If IsNull(Cells(z1, 9)) = True Then Cells(z1, 10) = "HI"
Next z1

Regards,
Per
 
S

Steve

I have code that I have tried in various ways yet I can not get the code to
recognize a blank cell.
  For z1 = 7 To 1300
        If Cells(z1, 9) = "" Then Cells(z1, 10) = "HI"
        If IsNull(Cells(z1, 9)) = True Then Cells(z1, 10) = "HI"
    Next z1

I only used the word hi to stick out on the sheet.

Instead of using If Cells(z1, 9) = "", use If IsEmpty(Cells(Z1,9)).
This will truly check for an empty cell. Doing it the other way can
result in cells looking like they are blank but are filled with spaces.
 
J

John Bundy

Worked for me just by specifying which sheet to use
If Sheets(1).Cells(z1, 9) = "" Then Sheets(1).Cells(z1, 10) = "HI"
 
R

Rpettis31

I discovered that I had used the wrong value "x" instead of Z in my code.
If Sheets(1).Cells(z1, 9) = "" Then Sheets(1).Cells(x1, 10) = "HI"

THanks all.
 

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