-
Empty vs Zero
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?
[VBA]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 [/VBA]
-
What is the type of the Dec_CC variable?
-
Did you see the typo ?
Dec_CC = ActiveSheet.Cells(21+ i, 1g).Value 'also tried = "" here
-
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?
-
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.
-
a Long can't be empty - its default value will be 0
-
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.
[vba]?isempty(Range("AJ34"))[/vba] And press the enter key to the result.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules