Consulting

Results 1 to 4 of 4

Thread: Easy question

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    31
    Location

    Easy question

    Probably this is an easy question, but I can't find out how to do it.
    How can I let VBA check if a cell is empty? I want to check 6 cells if they are empty, and if they're not empty, fill in another cell a formula.

    Please can somebody help me?

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    the IsEmtpy function will do this, e.g.
    If IsEmpty(ActiveCell) Then MsgBox "Active cell is empty"
    K :-)

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Posts
    31
    Location
    Can I also put a formatting in?
    Because other cells are also calculated and I want to put that color on white when the first column is empty.
    Please help again Killian

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    You can do anything you like!
    IsEmpty tests a Range object so you can use any of the Range methods or properties. For example:

    Sub test()
    Dim myRange As Range    'the range of cell you want to test
    Dim c As Range          'the cell you test each time
    Set myRange = ActiveSheet.Range("A1:A20")
    For Each c In myRange               ' for each cell in the range
            If IsEmpty(c) Then              'if the cell is empty
                c.Value = "I was empty"     'change the value
                c.Interior.Color = vbRed    'change the color
                'etc, etc...
            End If
        Next c
    End Sub
    K :-)

Posting Permissions

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