PDA

View Full Version : Empty vs Zero



snowdyce
10-23-2012, 12:55 PM
Hello Experts,

I am running into a snag in terms of an Empty value vs a Zero. I have this little if statement that loops for each month. It works correctly on all months except December. So it states if the selected cell IsEmpty, then make that variable (Dec_CC) empty/blank. This works on other Columns, but here it puts a Zero as the value for Dec_CC, even after it is approved on the initial If. I also tried to change the Then section to = "" and I get a runtime 13 error. Any thoughts?

If IsEmpty(ActiveSheet.Cells(21 + i, 16).Value) Then
Dec_CC = ActiveSheet.Cells(21+ i, 1g).Value 'also tried = "" here
Else: Dec_CC = Round(ActiveSheet.Cells(21 + i, 16).Value, 0)
End If

Aflatoon
10-24-2012, 02:14 AM
What is the type of the Dec_CC variable?

snb
10-24-2012, 02:21 AM
Did you see the typo ?

Dec_CC = ActiveSheet.Cells(21+ i, 1g).Value 'also tried = "" here

snowdyce
10-24-2012, 05:35 AM
The type is a Long. It is the same type as Jan-Nov which work fine and pull "Empty into the variable, but December pulls a 0, but there is no zero? could it be the format of the column of cells?

snowdyce
10-24-2012, 05:37 AM
Snb, yes I did see the error, i was changing some things around testing when i copied the code. The issue still happens when it is (21+i,16). Thanks.

Aflatoon
10-24-2012, 05:52 AM
a Long can't be empty - its default value will be 0

Kenneth Hobs
10-24-2012, 06:01 AM
Snowdyce, when posting a new thread that relates to another, that is fine if you are asking a new question. You can always post a link to your other thread if it relates somewhat. It saves you from rehashing an issue that has been solved.

To get an example file, see: http://www.vbaexpress.com/forum/showthread.php?p=278869

I use VBE's Immediate window to quickly test a snippet. The "?" is like Debug.Print. e.g.
?isempty(Range("AJ34")) And press the enter key to the result.