[Solved] VBA scripting for MS excel


I think this is what you meant, the following code loops through all rows with data, and for each row checks if the word “man” is inside that strings (using the Instr function).

Sub FindMan()

Dim FindString                  As String
Dim Sht                         As Worksheet

Dim LastRow                     As Long
Dim lRow                        As Long

' modify "Sheet1" to your sheet name
Set Sht = ThisWorkbook.Sheets("Sheet1")

With Sht
    ' find last row in Column "B"
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

    ' you can modify your searched word as you wish at the following line
    FindString = "man"

    ' loop through all rows with data in cells "B"
    For lRow = 2 To LastRow
        If InStr(1, .Cells(lRow, 2), FindString, vbTextCompare) > 0 Then
            .Cells(lRow, 3).Value = "Hello"  ' if found add "Hello" to the cell on the right > Column C
        End If
    Next lRow

    ' add header title for Column C
    .Cells(1, 3).Value = "Found man"    
End With

End Sub

1

solved VBA scripting for MS excel