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.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,266
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,530
Messages
5,602,200
Members
414,513
Latest member
junbuggle

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
Top