Using the Like operator properly

elbrodero

Senior Member
I have the following function:

For l = 3 To 100 Step 2
Str3 = Worksheets(2).Cells(l, 1).Value

If Right(Str2, 7) = Right(Str3, 7) Then Worksheets(3).Range("C6").Value = Worksheets(2).Cells(l, 4).Value
Next l

This works quite well, however sometimes I have the case that the value of Str2 has left out two zeros at the end but I would still like to copy the value. I thought of something like:

If "Right(Str2, 7)*" Like "Right(Str3, 7)" Then Worksheets(3).Range("C6").Value = Worksheets(2).Cells(l, 4).Value

But that doesn't work. Do you guys have any idea?

Diane Poremsky

Senior Member
so the values are something like ABC123456700 but sometimes the 00 are left off and you want to match the remaining 5?
so ABC1234567 = ABC123456700 ?

Something like this might work (have not tested it ) - maybe using If/elseif
If "Right(Str2, 7)*" Like "Right(Str3, 7)" Then Worksheets(3).Range("C6").Value = Worksheets(2).Cells(l, 4).Value
If "Right(Str2 & "00", 7 )" Like "Right(Str3, 7)" Then Worksheets(3).Range("C6").Value = Worksheets(2).Cells(l, 4).Value