doriannjeshi
Active Member
- Joined
- Apr 5, 2015
- Messages
- 338
- Office Version
- 365
- Platform
- Windows
Hi,
I need to delete the last 3 rows with VBA
I need to delete the last 3 rows with VBA
Sub DeleteLast3()
Dim lRow As Integer, i As Integer
lRow = Me.UsedRange.Rows.Count
For i = lRow To lRow - 2 Step -1
Me.Rows(i).EntireRow.Delete
Next i
End Sub
blockA | Attr | blockb | NR1 | NR2 |
12:00:00 AM | 2 | 29 | 8 | 0 |
12:00:00 AM | 2 | OMO | 1 | 0 |
12:00:00 AM | 2 | IDR | 1 | 0 |
12:00:00 AM | 2 | ICP | 2 | 1 |
12:00:00 AM | 2 | IMS | 1 | 0 |
12:00:00 AM | 2 | IVL | 1 | 0 |
12:00:00 AM | 2 | ITO | 2 | 0 |
12:00:00 AM | 2 | ITG | 1 | 1 |
12:00:00 AM | 2 | IFG | 1 | 0 |
12:00:00 AM | 2 | 37 | 9 | 0 |
12:00:00 AM | 2 | ISH | 1 | 0 |
28 | 2 | |||
48 | 4 | |||
1 | ||||
Sub MyDelete()
Dim lr As Long
' Find last row in column A with data
lr = Cells(Rows.Count, "A").End(xlUp).Row
' Delete last three rows
If lr >= 3 Then Rows(lr - 2 & ":" & lr).Delete
End Sub
Sub DeleterowAgain()
Dim LstCell As Range
Set LstCell = Cells(Rows.Count, "A").End(xlUp)
With LstCell
If .Row >= 3 Then .Offset(-2).Resize(3).EntireRow.Delete
End With
End Sub
yes the updated code:
Sub DeleteLast3()
Dim lRow As Integer, i As Integer
Dim lRow As Integer, i As Integer
Dim lRow As Long, i As Long
Sub Or_So_Maybe()
Sheets("Sheet1").Cells(Sheets("Sheet1").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row, 1).Offset(-2).Resize(3).EntireRow.Select
End Sub
Sheets("Sheet1").Cells(
Sub Or_So_Maybe2()
Sheets("Sheet1").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Offset(-2).Resize(3).EntireRow.Select
End Sub