简体   繁体   中英

VBA to check whether the Cell has specific text

I am trying to find if "Payment info" is present in a cell that contains a string

If the criteria is met then the code should add new text log to the string

"Supplier repay Payment info"

becomes

"Supplier repay log Payment info"

Can any one help please!

Use the Following UDF

Function CheckStr(cell As Range, srchString As String) As Boolean
    If InStr(UCase(cell.Value), UCase(srchString)) <> 0 Then
        CheckStr = True
    Else
        CheckStr = False
    End If
End Function

After re-reading your question i find it a little un-clear, the above code will search the value of a cell for certain string. I am not sure I fully understand what you are trying to achieve.

If the original text to change always contains the text "Supplier repay Payment info", then you could simply use the Find & replace command (Ctrl-h). Find "Supplier repay Payment info" and replace with "Supplier repay log Payment info".

For A1:A100

Set rng1 = Range("A1:A100")
rng1.Replace "Payment info", "log Payment info", xlPart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM