Skip to main content

Delete Rows From Excel Sheet

Public Function BIP_xlsDeleteRowRange (sSrcPath, sDestPath, sStartRow, sEndRow) ‘Create Excel object
    Set oExcel = CreateObject(“Excel.Application”)
    ‘Sets the application to raise no app alerts
    ‘In this case it will allow a file overwrite w/o raising a ‘yes/no’ dialog
    oExcel.DisplayAlerts = False
  
    ‘Open Book in Excel
    Set oBook = oExcel.Workbooks.Open(sSrcPath)
    ‘Set Activesheet
    Set oSheet = oExcel.Activesheet
  
    ‘Delete row range
    oSheet.Rows(sStartRow +”:”+ sEndRow).Delete
  
    ‘Save new book to Excel file
    oBook.SaveAs (sDestPath)
  
    ‘Close the xls file
    oExcel.Workbooks.Close()

End Function

Comments