Tim February 2016

String comparison using Like an wildcard not working

I have data in some cells in column B that look like Id# plus some number e.g 'Id# 85'

All the other cells have names in them FirstName LastName

I need to find the cells that have Id# in them, I am trying the following, but not working

Thanks

Sub test()
Dim ws As Worksheet
Dim i As Long

  Set ws = ThisWorkbook.Sheets("Elements")

  With ws
  For i = 2 To 180
    If .Cells(i, "B").Text Like "Id#" & "*" Then Do something
  Next i
End With

End Sub

Answers


neizan February 2016

Try this:

Sub test()
    Dim ws As Worksheet
    Dim i As Long
    Set ws = ThisWorkbook.Sheets("Elements")

    With ws
        For i = 2 To 180
            If Left(.Cells(i, "B").Text, 3) = "Id#" Then
                .Cells(i, "C").Value = True
            End If
        Next i
    End With
End Sub

Post Status

Asked in February 2016
Viewed 1,864 times
Voted 9
Answered 1 times

Search




Leave an answer