How do you go through each employee number and see if they have 2 codes to their ID?

jojo52479

New Member
Joined
Mar 2, 2017
Messages
24
I was given a project to go through each employee ID going back to the first employee and see when they switched from union to nonunion. Below is an example of my spreadsheet. Using VBA, what code would I be able to use to go through each EE# and determine when they switch to union codes 99, 87, and 88. Untimely, I want to only keep the EE# that went to those union codes and delete the EE that dont have these union codes. Any assistance could help. I have over 300K of lines so going one EE at a time wouldnt work.

[TABLE="width: 225"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]EE#[/TD]
[TD]Hire Date[/TD]
[TD]Union Code[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/10/1998[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]7/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TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]58C[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]3/11/1988[/TD]
[TD]8[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If you click the Debug button, it will highlight a line of code. Which line?
 
Upvote 0
In that case put the cursor anywhere in the code & press F8, to step through the code line by line until you get an error.
 
Upvote 0
The bold area turns yellow first.

Sub KeepUnionCode()
Dim Cl As Range
Dim Flg As Boolean

With CreateObject("scripting.dictionary")
For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
Select Case Cl.Offset(, 2).Value
Case 87, 88, 99: Flg = True
Case Else: Flg = False
End Select
If Not .exists(Cl.Value) Then
If Flg Then .Add Cl.Value, Nothing Else .Add Cl.Value, CStr(Cl.Value)
ElseIf Not IsEmpty(.Item(Cl.Value)) Then
If Flg Then .Item(Cl.Value) = Empty
End If
Next Cl
Range("A1").AutoFilter 1, .items, xlFilterValues
ActiveSheet.AutoFilter.Range.Offset(1).EntireRow.Delete
Range("A1").AutoFilter
End With
End Sub
 
Upvote 0
In that case, try rebooting it.
If it still doesn't work in the VBE click Tools > references > scroll down & look to see if there is Microsoft Scripting Runtime. If it's there put a tick in the checkbox & just below you should see Location & Standard. Do you have details there?
 
Upvote 0
In that case I'm not sure.
It maybe that something on your system is corrupted.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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