+ Reply to Thread
Results 1 to 4 of 4

Delete Empty Cells With VBA

Hybrid View

markrennolds Delete Empty Cells With VBA 11-30-2010, 11:39 AM
stnkynts Re: Delete Empty Cells With... 11-30-2010, 12:06 PM
markrennolds Re: Delete Empty Cells With... 11-30-2010, 12:25 PM
stnkynts Re: Delete Empty Cells With... 11-30-2010, 02:46 PM
  1. #1
    Registered User
    Join Date
    07-15-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    77

    Delete Empty Cells With VBA

    Hi All

    I need a vba that will delete all cells with value of "" or zero, not deleting the row or the column just deleting any contents, so that a hide row macro ( which i have set up) will not pick up these "" values & regard them as nonblank.

    Thanks
    Mark
    Last edited by markrennolds; 11-30-2010 at 12:26 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Delete Empty Cells With VBA

    Hello friend,

    I am a little confused as to whether the cells contain the quotation marks or if they are blank and you used quotation marks to illustrate they are blank. In response to if the cell has a value of zero here is a loop which will work for you.

    Option Explicit
    
    Sub Deletevalue()
    Dim iCell As Range
    
    For Each iCell In Range("A1:D100")
        If iCell = 0 Then
            iCell.Delete
        End If
    Next iCell
    
    End Sub
    Note: You will want to adjust the range to meet your needs. Also, since i wasn't sure what the range was this may not be the best way to do what you want to do. For example if the range is really big this macro will be really slow. Let me know.

  3. #3
    Registered User
    Join Date
    07-15-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Delete Empty Cells With VBA

    Hi there

    Thanks for the code, i realised what i needed to do & adapted it to suit. I have included the code below to help anyone who might see it & need similar.

    Cheers
    Mark

    Sub Deletevalue()
    Dim iCell As Range
    
    For Each iCell In Range("A5:A32")
        If iCell = 0 Then
            iCell.ClearContents
        End If
    Next iCell
    
    End Sub

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Delete Empty Cells With VBA

    Just wanted to update a better way for future readers now that I see what you want to do

    Try:
    Option Explicit
    
    Sub Deletevalue()
    Dim lastrow As Long
    Dim iCell As Long
    
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    
    For iCell = 3 To lastrow
        If Range("A" & iCell) = 0 Then
            Range("A" & iCell).ClearContents
        End If
    Next iCell
    
    End Sub
    This way we only focus on column A rather than all the cells. Much faster

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1