PDA

View Full Version : [SOLVED:] Compare one worksheet to multiple worksheets



had1015
10-26-2016, 03:29 AM
Hi,

I would like to create a macro to compare one worksheet to multiple sheets in the same workbook. Worksheet 'Master" column F contains ID. Other worksheets columns C contains ID as well. I'd like to find where ID in column F on the "Master" sheet matches all other sheets columns C except "Index" sheet and copy the Manager from worksheet "Master" column H to other sheets column P. So all sheets except Master and Index would be updated in column P. Any assistance you provide would be greatly appreciated.

mana
10-26-2016, 04:27 AM
Option Explicit

Sub test()
Dim dic As Object
Dim ws As Worksheet
Dim v, i As Long
Dim c As Range

Set dic = CreateObject("scripting.dictionary")

v = Sheets("Master").Range("a1").CurrentRegion.Value

For i = 2 To UBound(v)
dic(v(i, 6)) = v(i, 8)
Next

For Each ws In Worksheets
If ws.Name <> "Master" And ws.Name <> "Index" Then
For Each c In ws.Range("a1").CurrentRegion.Columns("c").Cells
If dic.exists(c.Value) Then
c.EntireRow.Range("p1").Value = dic(c.Value)
End If
Next
End If
Next

End Sub

had1015
10-26-2016, 05:13 AM
Thanks mana it works just as I wanted.