Tim Richards
Tim Richards

Reputation: 324

Using VBA to search for a string (fuzzy logic)

I cobbled together this a few years ago and now I need it tweaked slightly but I'm very rusty with VBA so could do with some advice:

Sub Colour_Cells_By_Criteria()

Dim myRange As Range
Dim myPattern As String
Dim myLen As Integer
Dim myCell As Range

Set myRange = Range("A1:A1000")

myPattern = "*1*"

myLen = 4

Application.ScreenUpdating = False

Application.StatusBar = "Macro running, please wait...."

For Each myCell In myRange
  With myCell
    If (.Value Like myPattern) And (Len(.Value) = myLen) Then
      myCell.Interior.Color = 65535
      myCell.Font.Bold = True
    End If
  End With
Next

Application.ScreenUpdating = True

Application.StatusBar = False

End Sub

Rather than colouring and bolding any cells that are captured by the logic, I'd like to put the word "MATCH" in the same row in column B.

Any nudges in the right direction would be appreciated.

Upvotes: 2

Views: 2430

Answers (1)

Tim Williams
Tim Williams

Reputation: 166126

myCell.Offset(0,1).Value="Match"

Upvotes: 3

Related Questions