excel vba delete all rows after certain row code example

Example 1: excel vba delete rows in range

' Removes 3rd row
ThisWorkbook.Worksheets(1).Rows(3).EntireRow.Delete
' Just to clear cells without removing the row
ThisWorkbook.Worksheets("Feuil1").Rows(3).Cells.ClearContents
' Removes 3rd row of a range
Range("My_RANGE").Rows(3).EntireRow.Delete

Example 2: excel vba delete empty rows

' Deletes empty rows
dim rRange As Range, rowsCount As Long, i As Long
Set rRange = ActiveSheet.Range("A1:B100")
rowsCount = rRange.rows.Count
For i = rowsCount To 1 Step -1
    If WorksheetFunction.CountA(rRanges.rows(i)) = 0 Then 
        rRange.rows(i).Delete
    End If
Next

Example 3: vba excel delete every other row

Sub Delete_Even()
 
 Application.ScreenUpdating = False
lr = Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
 
If lr Mod 2 = 0 Then
Else
lr = lr - 1
End If
 
For i = lr To 1 Step -2
    Rows(i & ":" & i).Delete Shift:=xlUp    
Next i
 
  Application.ScreenUpdating = True
 
End Sub

Tags:

Vb Example