Hi Phil,
It is because Excel needs to know we are working with numbers.
So we can do a calculation to let Excel know:
Sub StringComp()
Dim mRow As Integer
For Each cell In Range("A1:A3")
mRow = 0
Do
mRow = mRow + 1
If cell.Value - Mid(Range("B" & mRow), 9, 4) = 0 Then
Cells(cell.Row, "C").Value = Range("B" & mRow).Value
End If
Loop Until mRow = 10
Next cell
End Sub
Or we can declare another variable:
Sub StringComp()
Dim mRow, MyString As Integer
For Each cell In Range("A1:A3")
mRow = 0
Do
mRow = mRow + 1
MyString = Mid(Range("B" & mRow), 9, 4)
If cell.Value = MyString Then Cells(cell.Row, "C").Value = Range("B" & mRow).Value
End If
Loop Until mRow = 10
Next cell
End Sub
Best regards,
Trowa