Consulting

Results 1 to 6 of 6

Thread: Solved: Delete Empty Cells

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Posts
    49
    Location

    Solved: Delete Empty Cells

    Hi Guys,

    I am trying to make a simple macro that deletes empty cells, but for some reeason the code below keeps skipping over any empty cells it encounters... Essentially, nothing is happening.. lol.

    Any help with this would be greatly appreciated!

    Kind Regards,

    Giri

    [vba]
    Public Sub DeleteEmpty()

    Dim row As Integer
    Dim c
    row = Range("D").End(xlDown).row

    For Each c In Range("D1" & row)
    c.Select

    If IsEmpty(ActiveCell) = True Then
    ActiveCell.Delete
    End If

    Next c
    End Sub
    [/vba]

  2. #2
    Would this work?
    [vba]
    Range("D").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    [/vba]
    Last edited by Aussiebear; 07-07-2011 at 09:08 PM. Reason: Adjusted to use the correct tags around the code section

  3. #3
    VBAX Regular
    Joined
    Oct 2010
    Posts
    49
    Location
    Hi Jolivanes,

    Thanks for the reply. I tried what you suggested but I received an error message:

    "RunTime Error: 1004 No Cells were Found"

    Thanks for your help.

    Kind Regards,

    Giri

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]Public Sub DeleteEmpty()

    Dim lastrow As Long
    Dim i As Long
    lastrow = Range("D").End(xlDown).row

    For i = lastrow to 1 step -1

    If IsEmpty(Cells(i,"D").Value2) Then

    Cells(i, "D").Delete Shift:=xlShiftUp
    End If
    Next i
    End Sub [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Oct 2010
    Posts
    49
    Location
    Thanks for the replies xld and Jolivane.

    Jolivane, I tried your suggestion on another worksheet and it was perfect! Not sure what was going on when I tried it before...

    Kind Regards,

    Giri

  6. #6
    Glad you have it sorted.
    Often cells appear to be empty but are not.

Posting Permissions

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