Delete 10 rows but omit columns A, B and C

FatWhale38

New Member
Joined
Nov 2, 2017
Messages
8
Office Version
  1. 2007
Platform
  1. Windows
Hello

I found the following code on another thread:

Code:
Sub Delete_Last_10_Rows()
Dim rLastRow As Range
Set rLastRow = Cells(Rows.Count, "C").End(xlUp)
 
'now delete last 10 rows:
rLastRow.Offset(-9).Resize(10).EntireRow.Delete
 
 MsgBox ("The last 10 Sets of Data is now Deleted")
End Sub

Many thanks to the contributors of that thread that came up with that.

I wanted to add on to that thread, but was not sure about hijacking it hence this thread.

I want to modify the above code so it deletes the last ten rows from column D onwards (the last column is a variable) :(

I initially wanted to do it as an offset from the last row, but couldn't quite figure it out either.

I hope you all can help me.

Many thanks!!!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Here is how I would attack this issue

Code:
Option Explicit


Sub delLast10()
    Dim lr As Long, lc As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Range(Cells(lr - 9, 4), Cells(lr, lc)).Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top