Results 1 to 7 of 7

Is IsBlank() just for Excel spreadsheet and not for VBA?

This is a discussion on Is IsBlank() just for Excel spreadsheet and not for VBA? within the Excel Questions forums, part of the Question Forums category; Is it true that IsBlank() can only be used inside an Excel cell, and not in VBA code inside your ...

  1. #1
    New Member
    Join Date
    Mar 2004
    Posts
    30

    Default Is IsBlank() just for Excel spreadsheet and not for VBA?

    Is it true that IsBlank() can only be used inside an Excel cell, and not in VBA code inside your workbook? If so, then would the best bet be to test the length of the value of the cell (in VBA) to determine whether it's blank or not??? Is there a list anywhere of which functions can be used only in Excel, which ones only in VBA, and which ones in both? I'm finding this very confusing.
    Thanks a lot.

  2. #2
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Is IsBlank() just for Excel spreadsheet and not for VBA?

    One way amongst many...

    If rng.Formula = vbNullString Then
    ...code if blank...
    End If
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  3. #3
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: Is IsBlank() just for Excel spreadsheet and not for VBA?

    To answer one question...just test the contents of the cell in VBA...
    Code:
    If Range("A1") = vbNullString Then 'or it is blank
        Msgbox "Blank Cell"
    End If

  4. #4
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Is IsBlank() just for Excel spreadsheet and not for VBA?

    Note that Tommy's first will return true if the value is blank, i.e. [A1] could hold a formula like =IF(B1=0,"","x") and if [B1] is zero, you'd get a true (which you may or may not want).
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  5. #5
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default

    As an equivalent for ISBLANK in VBA use

    Code:
    IsEmpty(RangeReference)
    Regards,
    Martin

  6. #6
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Is IsBlank() just for Excel spreadsheet and not for VBA?

    Nifty, Martin. I'd not thought of dropping a range ref inside IsEmpty() before. Testing in the Immediate window, it appears to work quite nicely with anything except a non-contiguous range.
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  7. #7
    Board Regular MartinK's Avatar
    Join Date
    Oct 2003
    Location
    Prague, CZ / Zagreb, HR
    Posts
    384

    Default Re: Is IsBlank() just for Excel spreadsheet and not for VBA?

    dropping a range ref inside IsEmpty() before
    I am sorry Greg, that's a misunderstanding. IsEmpty checks just the first cell of the range, therefore:
    Sub TestBlanks()
    Dim cl As Range
    '
    ' this will work
    If [AND(ISBLANK(A1:A10))] Then MsgBox "All Empty"
    '
    ' and this will not
    Set cl = [A1:A10]
    If IsEmpty(cl) Then MsgBox "All Empty"
    '
    ' and this of course works
    Set cl = [A1]
    If IsEmpty(cl) Then MsgBox cl.Address & " Empty"
    End Sub


    Sorry for the misleading contribution

    Best regards,
    Martin

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com