VBA IsNumeric selects blank cell

  • When B13 is blank (No value, no formula and formatted as General) this code still selects and copies, instead of selecting B12 and copying. Where is my error ?

    Code
    Windows("Premier Current.xls").Activate
         If IsNumeric(Range("B13").Value) Then
        Range("B13").Copy
            Windows("Premier1").Activate
            Range("B12").PasteSpecial Paste:=xlValues, Operation:=xlPasteSpecialOperationAdd
        Else
            Range("B12").Copy
            Windows("Premier1").Activate
            Range("B12").PasteSpecial Paste:=xlValues, Operation:=xlPasteSpecialOperationAdd
            End If
  • Re: VBA IsNumeric selects blank cell


    Hi Diego,


    VBA will return a value of True if you test a blank cell for IsNumeric. You need to change your second line of code to measure the length of the field as well:


    Code
    If IsNumeric(Range("B13").Value) And Len(Range("B13").Value) > 0 Then


    Hope this helps.


    Regards,
    Batman.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!