Macro to delete specific rows according to data given in second worksheet

ParaSitius

New Member
Joined
Nov 11, 2013
Messages
11
Hi all,

I've been doing a lot of searching trying to find a macro that can help me delete specific rows from a worksheet using data given in a second worksheet.

As an example:

Sheet1 has 500 rows with data contained within
Sheet2 has in the A column, numbers 3, 80, 212 and 415.

I need the macro to delete rows 3, 80, 212 and 415 from worksheet one. The macro would also need to be able to cover different size files as some can be several thousand rows.

My knowledge of macros extend as far as hitting the record button so I'm hoping for something that isn't too complex to understand.

Apologies if this has already been answered elsewhere.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:

On "Sheet2" in column "A" put all the row numbers you want deleted from "Sheet1"
Be sure and have no other information in this column "A"
And then run this script
Code:
Sub Delete_Rows()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Sheets("Sheet2").Activate
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = Lastrow To 1 Step -1
Sheets("Sheet1").Rows(Sheets("Sheet2").Cells(i, 1).Value).Delete
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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