+ Reply to Thread
Results 1 to 2 of 2

[SOLVED] deleting empty cells

Hybrid View

  1. #1
    Registered User
    Join Date
    12-27-2011
    Location
    Bothell
    MS-Off Ver
    Excel 2010
    Posts
    5

    [SOLVED] deleting empty cells

    NEVER MIND I FIGURED IT OUT, BUT THANKS ANYWAY.


    I have data with empty cells throughout in a column. My goal is to erase the empty cells in the column with the data without disturbing the other columns and end up with no empty cells in between each piece of data. The problem is that the sub routine bellow is deleting all the cells including the ones with the data.


    Sub erasewe()
    
    For i = 1 To 10000
    If IsEmpty(ActiveCell) Then
    ActiveCell.Delete Shift:=xlUp
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Next i
    End Sub
    Last edited by Truss123; 02-13-2012 at 01:35 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: deleting empty cells

    Hi Truss123, perhaps the following?
    Sub erasewe()
    
        Dim Ws As Worksheet
        Dim RngToSearch As Range, rc As Range
        
        Application.ScreenUpdating = False
        Set Ws = Worksheets("Sheet1")
        Set RngToSearch = Ws.Range(Ws.Cells(1, ActiveCell.Column), Ws.Cells(1000, ActiveCell.Column))
        
        For Each rc In RngToSearch
            If IsEmpty(rc) Then
                rc.Delete shift:=xlUp
            End If
        Next rc
        Application.ScreenUpdating = True
    
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ 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