vba excel how to replace part of a string code example
Example 1: excel vba replace part of a string
Function IfInReplace$(s$, substr1$, replacement$, Optional CaseSensitivity = vbTextCompare)
If InStr(1, s, substr1, CaseSensitivity) Then s = Replace(s, substr1, replacement, , , CaseSensitivity)
IfInReplace = s
End Function
MsgBox IfInReplace("abc123def", "123", "")
Example 2: macro for replacing text in excel
Worksheets("Sheet1").Columns("A").Replace _
What:="SIN", Replacement:="COS", _
SearchOrder:=xlByColumns, MatchCase:=True