Can someone help me on removing specific rows in Excel and then shift cells up by using a macro? E.g. I need to delete rows 8, 14 and 79.
Thanks in advance for your help
Can someone help me on removing specific rows in Excel and then shift cells up by using a macro? E.g. I need to delete rows 8, 14 and 79.
Thanks in advance for your help
Try:
Option Explicit
Sub test()
Dim LastRow As Long, i As Long
With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '<- Find lastrow of column A where we assume data appears
For i = LastRow To 1 Step -1 '<- Loop from bottom to top
If i = 8 Or i = 14 Or i = 79 Then '<- If row is 8 or 14 or 79
.Rows(i).EntireRow.Delete '<- Delete row
End If
Next i
End With
End Sub
Another Solution suggested by Pᴇʜ (see comments):
Option Explicit
Sub test()
ThisWorkbook.Sheets("Sheet1").Range("8:8,14:14,79:79").EntireRow.Delete
End Sub
Another Solution:
Option Explicit
Sub test()
With ThisWorkbook.Sheets("Sheet1")
Union(.Rows(8), .Rows(14), .Rows(79)).Delete Shift:=xlUp
End With
End Sub