If Range ("C22") <> = 0

  • Thread starter Thread starter Lav
  • Start date Start date
L

Lav

Embarressing I thougth I knew the answer

My macro populates the cell if the relevant cell it is reading from
(in another wb has data in it).

If there is no data in it how do I put a 0 in that cell (C22)?

Thanks
 
if range("c22").value = "" then 'it has no data
range("c22").value = 0
end if

i think that's what you want.
:)
susan
 
Embarressing I thougth I knew the answer

My macro populates the cell if the relevant cell it is reading from
(in another wb has data in it).

If there is no data in it how do I put a 0 in that cell (C22)?

Thanks

I like Gary's Student's IsEmpty method, but I probably would have used
the cells(22,3) reference rather than range("c22") - that' probably
just a personal pref, idk.

Susan's suggestion of range("c22").value="" has failed me before.
I've had more luck with =Empty than ="", not sure why actually.
 
IsEmpty is nice because it finds TRUE empties rather than pseudo-empties.

Start with a new, fresh worksheet and in A1 enter:
=""

If you now copy A1 and:
Edit > Paste Special > Values into A2 and then run:

Sub HowEmptyIsIt()
For Each r In Range("A1:A3")
MsgBox (r.Address & IsEmpty(r))
Next
End Sub

VBA will tell you that there is SOMETHING in A1 and A2.

Same behavior as =COUNTA() and =ISBLANK() in the worksheet.
 

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

Back
Top