Find Last Row counting from the 2nd row down?

question610

New Member
Joined
Jul 3, 2017
Messages
29
I want to delete all the cells from Row 2 down for column 1 and 2. What is the best way to do it?

I tried this but the lastRow is simply the last row number which does not help because I would delete the first row too. I need something like offset...what's the best way?

Code:
lastRow = Range("B2").End(xlDown).Row ' 
Set DeleteRange = ActiveSheet.Range("A2:A" & lastRow, "B2:B" & lastRow)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try
Code:
lastRow = Cells(Rows.Count, 2).End(xlUp).Row

If column B is ever empty then lastRow will be 1 If you want to keep your range from including row one then test if lastRow is 1 then lastRow is 2
Code:
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
If lastRow = 1 Then lastRow = 2
 
Upvote 0
Replace this
Code:
Set DeleteRange = ActiveSheet.Range("A2:A" & lastRow, "B2:B" & lastRow)
with
Code:
Set DeleteRange = ActiveSheet.Range("A2:B" & lastRow)
 
Upvote 0
An ugly possible alternative :biggrin:.....

Code:
Sub deleteme()
    On Error Resume Next
    Range(Range("A2"), Range("A:B").Find("*", , xlValues, , xlByRows, xlPrevious)).ClearContents
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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