Results 1 to 2 of 2

Thread: Vb script Delete Empty Rows Excel

  1. #1

    Thread Starter
    Registered User
    Join Date
    Nov 2021
    Posts
    1

    Vb script Delete Empty Rows Excel

    Need some help writing a VB script that gets the used range within excel then loops through each row within the used range and if the whole row is empty it deletes that row in excel.

    The following code im using just deletes all the rows in the used range.

    Any help is Greatly appreciated.

    Code:
    Dim objXL, WB, MyRange 
    On Error Resume Next
    Set objXL = GetObject(, "Excel.Application")
    Set WB = objXL.ActiveWorkbook
    Set WS = objXL.ActiveWorkbook.Sheets(1)
    
        Set MyRange = WS.UsedRange
        
        
    'Start reverse looping through the range.
        For iCounter = MyRange.Rows.Count To 1 Step -1
        
    'If entire row is empty then delete it.
           If objXL .CountA(Rows(iCounter).EntireRow) = 0 Then
           WS.Rows(iCounter).Delete
           End If
    'Increment the counter down
        Next

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Vb script Delete Empty Rows Excel

    For VBA, but can probably be adapted for use with VBScript:

    https://www.ablebits.com/office-addi...k-lines-excel/

Posting Permissions

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



Click Here to Expand Forum to Full Width