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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
18,714
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,673
Messages
5,838,708
Members
430,566
Latest member
ChanchalSingh

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