Delete all rows up to a certain number

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have a sheet and have data in column A:G in AA1 i have a number (i.e.1100)
now this number represents a number in Column A (Not the row number)
so what i want is a macro that can delete all rows from two to the number in AA1
please help if you can
Thanks
Tony
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try something like this.
Code:
Range("A2:A" & Range("AA1").Value).Resize(, 7).Delete xlShiftUp
 
Upvote 0
Try this:
VBA Code:
Sub DeleteRows()
Dim i As Long, Lr As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
i = Application.WorksheetFunction.Match(Range("AA1"), Range("A2:A" & Lr), 0)
Range("A2:A" & i).Resize(, 7).Delete xlShiftUp
End Sub
 
Upvote 0
Another option
VBA Code:
Sub tonywatson()
   Range("A2", Range("A:A").Find(Range("AA1").Value, , , xlWhole, , , False, , False)).EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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