Consulting

Results 1 to 7 of 7

Thread: Empty vs Zero

  1. #1
    VBAX Regular
    Joined
    Oct 2012
    Posts
    35
    Location

    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]

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    What is the type of the Dec_CC variable?
    Be as you wish to seem

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Did you see the typo ?

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

  4. #4
    VBAX Regular
    Joined
    Oct 2012
    Posts
    35
    Location
    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?

  5. #5
    VBAX Regular
    Joined
    Oct 2012
    Posts
    35
    Location
    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.

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    a Long can't be empty - its default value will be 0
    Be as you wish to seem

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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
  •