View Single Post
 
Old 06-11-2022, 01:24 PM
Venteux Venteux is offline Windows 10 Office 2019
Novice
 
Join Date: May 2021
Posts: 22
Venteux is on a distinguished road
Default Compare columns in two worksheets for similar text

Hi all,


I'm trying to figure out how to compare a column of names in one worksheet to a column of names in a second worksheet in the same workbook. I'm using the LIKE operator but it doesn't do what I'm looking for.


Column one will have names as Last Name, First Name
Column two has names as First Name Last Name


I'd like to find out if a name in sheet 1 doesn't appear in sheet 2 and vice versa. I don't know if this is even possible because obviously two different people might have the same first name but different last name so I don't want that name to be skipped.

I've attached a sample of my workbook for reference.

I'm obviously new at excel vba so any help is appreciated!


Code:

Sub Test2()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim Name1 As String
Dim Name2 As String
Dim n As Long

Set ws1 = Sheets("Form4A")
Set ws2 = Sheets("Form4B")

For n = 3 To 250
Name2 = ws1.Range("A" & n).Value
Name1 = ws2.Range("B" & n).Value

If Name2 Like Name1 Then

Else

ws2.Cells(Rows.Count, "E").End(xlUp).Offset(1).Value = Name1 & " " & "or" & Name2 & " " & "does not appear in both Form 4A and 4B."

End If

Next n

End Sub
Attached Files
File Type: xlsm SampleWorkbook.xlsm (20.2 KB, 7 views)
Reply With Quote