I am new to VBA and I would like to do a partial string (or cell) match between two sheets.
An example of Name1 would be "IT executive Sally Lim"
An example of Name2 would be "Sally Lim"
Name1 = Sheets("Work").Cells(RowName1, ColName1)
Name2 = Sheets("Roster").Cells(RowName2, ColName2)
'This condition doesn't work
If Name1 = "*" & Name2 & "*" Then
'The "Name2" comes out with a compile error: Invalid Qualifier
Name2.Font.Strikethrough
Exit Do
Else
End If
However, it is not working. When I run the coding, either nothing happens or an error pops out. Please help
Edited coding:
If ShiftName Like "*" & CashName & "*" Then
CashName.Font.Strikethrough = True
The strikeout portion has been solved and it does not shows the "Compile Error" anymore after I change my declaration from "string" to "range" as proposed by John Coleman.
I tested by changing Name1 and Name2 to both Sally and then use the following condition for strikeout and it works. I believed that it is the "*" that has made the condition unworkable.
If ShiftName Like CashName Then
CashName.Font.Strikethrough = True
How can a partial match be done by changing the condition accordingly?
SECOND EDIT:
MY BAD! I realised that my Name1 was in CAPTIALS.