+ Reply to Thread
Results 1 to 3 of 3

Delete the Blank lines

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2011
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    7

    Delete the Blank lines

    Hi,

    I have a dump of xls files in a folder, all these files have blank lines in them , can you give me some idea on how to write a macro which will delete the blank lines from all the files in a particular folder.

    Thx,Bds

  2. #2
    Registered User
    Join Date
    08-08-2011
    Location
    Warwick
    MS-Off Ver
    MS365
    Posts
    53

    Re: Delete the Blank lines

    I'm not sure how to delete blanks from all files within a folder... but a quick work-around option might be to place a simple macro in the "Workbook_Open" function of each individual sheet...

    Private Sub Workbook_Open()
    Range("A1").Select
    For x = 1 To 1000 (OR HOWEVER MANY ROWS YOU HAVE)
        If ActiveCell.Value <> "" Then
           ActiveCell.Offset(1, 0).Select
        Else
            Selection.EntireRow.Delete
        End If
    Next x
    End Sub

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Delete the Blank lines

    reachbds,

    Give the following a try. It will prompt you to select a folder, and then remove blank rows from each worksheet in each .xls file in that folder.
    Sub tgr()
        
        Dim strFldrPath As String
        With Application.FileDialog(msoFileDialogFolderPicker)
            .Show
            On Error Resume Next: strFldrPath = .SelectedItems(1)
        End With
        If strFldrPath = vbNullString Then Exit Sub
        
        Dim CurrentFile As String: CurrentFile = Dir(strFldrPath & "\" & "*.xls*")
        Dim wb As Workbook
        Dim ws As Worksheet
        Dim cIndex As Long
        
        Application.ScreenUpdating = False
        While CurrentFile <> vbNullString
            Set wb = Workbooks.Open(strFldrPath & "\" & CurrentFile)
            For Each ws In wb.Sheets
                With ws.UsedRange
                    For cIndex = 1 To .Columns.Count
                        .AutoFilter cIndex, "="
                    Next cIndex
                    .Offset(1).EntireRow.Delete xlShiftUp
                    .AutoFilter
                End With
            Next ws
            wb.Close True
            CurrentFile = Dir
        Wend
        Application.ScreenUpdating = True
        
    End Sub


    Hope that helps,
    ~tigeravatar

+ 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