How to delete all data in the all worksheets except first row in each sheet?
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Range("a2").EntireRow.Resize(sh.Rows.Count - 1).Delete
In excel we selected the entire worksheet and then do Format > Column -> Autofit selection and Format > Row -> Autofit
How we can do this in VBA?
How to delete the entire row if the certain text is present in column?
Following procedure will delete the entire row if the certain text is present in the column(s)
This example deletes the entire row if it finds “error” in column CD
Public Sub DeleteContaining()
Dim Row As Long
Application.ScreenUpdating = False
For Row = .UsedRange.Row + .UsedRange.Rows.Count - 1 To .UsedRange.Row Step -1
If InStr(1, .Cells(Row, "CD") & "", "error") > 0 Then .Rows(Row).Delete
Application.ScreenUpdating = True