fadetograham
New Member
- Joined
- Jul 6, 2015
- Messages
- 39
Hi everyone
I have a workbook with approx. 20 sheets, 10 with the same list of people and then a master list which each of those 10 sheets is looking up for further info.
I've written some code but am missing the final piece of the jigsaw, I want to loop through each sheet where there is the person list, check the list in that sheet and make sure it has all of the people listed in the master list.
The code I've written works but if the master list is sorted differently to the individual sheets then it adds them.
Code is below and any help is greatly appreciated.
I have a workbook with approx. 20 sheets, 10 with the same list of people and then a master list which each of those 10 sheets is looking up for further info.
I've written some code but am missing the final piece of the jigsaw, I want to loop through each sheet where there is the person list, check the list in that sheet and make sure it has all of the people listed in the master list.
The code I've written works but if the master list is sorted differently to the individual sheets then it adds them.
Code is below and any help is greatly appreciated.
Code:
Sub Add_New_Driver()
Dim ws As Worksheet
Dim wsml As Worksheet
Dim lr As Long
Dim mllr As Long
Dim a As Long
Dim b As Long
Set wsml = ThisWorkbook.Worksheets("Master List")
wsml.Activate
mllr = Cells(Rows.Count, 1).End(xlUp).Row
For Each ws In ThisWorkbook.Worksheets
If (ws.Name = "AR PDP ADR") Or (ws.Name = "Smiths System") Or (ws.Name = "HGV Licence Expiry") Or (ws.Name = "TBTs") Or (ws.Name = "D&A Test") _
Or (ws.Name = "UWSO Pre Start") Or (ws.Name = "UWSO Load") Or (ws.Name = "UWSO Discharge") Or (ws.Name = "UWSO Drive") Or (ws.Name = "Bi Annual Medical") Then
ws.Activate
lr = Cells(Rows.Count, 1).End(xlUp).Row
For a = 2 To mllr
b = 2
For b = 2 To lr
If wsml.Cells(a, 1) = ws.Cells(b, 1) Then
Exit For
ElseIf wsml.Cells(a, 1) <> ws.Cells(b, 1) Then
lr = lr + 1
ws.Cells(lr, 1) = wsml.Cells(a, 1)
End If
Next
Next
End If
Next
End Sub
Last edited by a moderator: