VBA Code:
Public Sub comparator()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim note As Range
Set ws1 = ThisWorkbook.Worksheets("Sheet1")
Set ws2 = ThisWorkbook.Worksheets("Sheet2")
Set note = Worksheets("Sheet2").Range("D:D")
Stop
For Each ws2 In ws1.Rows
If ws1.Cells(1, 1) = Space(0) Then
Exit For
Else
For Each ws2 In ws2.Rows
If ws2.Cells(1, 1) = Space(0) Then
Exit For
Else
If ws2.Cells(1, 2) = ws1.Cells(1, 2) Then
note.Copy (ws1.Cells(1, 4))
End If
End If
Next ws2
I'm brand new to VBA, and coding anything whatsoever. Up to this point everyone has been just doing the Ctrl+F thing for dozens of entries, and I've gotten annoyed at the status quo. I know a bit of code can automate this so I've taken it upon myself to try and learn VBA (maybe C# is next). The purpose of this is to compare two lists of employees and find a match. Upon finding a match, it will copy the item in sheet 2 column D to the same column in sheet 1. I know the final line is wrong but I can't figure out how to make it work. I think I've missed declaring a variable but I can't figure out what I need to declare.
Last edited by a moderator: