Macro to delete rows based on muliple values (300+) in a column.

dboatswain

New Member
Joined
Dec 18, 2016
Messages
3
Hi everyone,

In the past I have used the formula below to delete rows based on particular values.

Sub Two()
Application.ScreenUpdating = False
With Sheets("Indigenous_Hours_Program").Range("F1", Range("F" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:=Array("6346", "6331", "4365", "6150", "2199", "2199", "4251", "6083", "6122", "2406", "2017", "2012", "2094", "2099", "2117", "5141", "5041"), Operator:=xlFilterValues
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Application.ScreenUpdating = True

End Sub

However I have been given a large report (2000+ lines), where I need to exclude (delete) employees (400+) based on employee number (we have no other defining attribute unfortunately, it's an external report).


I have tried updating the above formula with employee numbers, however I get errors on stacking and syntax ...

I hope someone can please help me!

Oh and I have no idea how to code, very basic understanding :)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,602
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Do you mean any employee with the employee number greater than 400 ??

where I need to exclude (delete) employees (400+)
 
Upvote 0

dboatswain

New Member
Joined
Dec 18, 2016
Messages
3
Oh I wish! I need to delete a large number of rows based on unique employee numbers ...

i.e. exclude Employee Numbers:

88899663
88212111
68721111
88823111
+ hundreds more!
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,602
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
OK....but based on what criteria ??
Greater than a certain number ??
Appears more than once ??
 
Upvote 0

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
5,125
Hi dboatswain,

Welcome to MrExcel!!

If you have the list of employee numbers to be deleted on a separate tab you could write a VLOOKUP formula in an unused column nested in a IFERROR function that would flag the matches with some text (say "Delete Me") and return nothing for no matches. You could then use this column to delete the matches i.e. all "Delete Me" entries.

HTH

Robert
 
Upvote 0

Forum statistics

Threads
1,191,399
Messages
5,986,363
Members
440,020
Latest member
IfsandSums

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