FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,381
- Office Version
- 365
- 2016
- Platform
- Windows
I found this macro which works fine for one word, but not sure how not modify for changing an array of words.
Right now the one word within the string I'm looking for is "DET:", but I'd like to add many others.
Could somebody help me with the next step?
Right now the one word within the string I'm looking for is "DET:", but I'd like to add many others.
Could somebody help me with the next step?
Code:
Sub ReplaceStr()
Dim OriVal As String, RepWhat As String, RepWith As String, TempStr As String
Dim Cell As Range, Rng As Range
Dim RepLen As Integer
Application.ScreenUpdating = False
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
RepWhat = "DET:"
RepWith = "Det:"
RepLen = Len(RepWhat)
For Each Cell In Rng
OriVal = Cell.Value
Do Until InStr(OriVal, RepWhat) = 0
TempStr = TempStr & Left(OriVal, InStr(OriVal, RepWhat) - 1) & RepWith
OriVal = Right(OriVal, Len(OriVal) - ((InStr(OriVal, RepWhat) - 1) + RepLen))
Loop
Cell.Value = TempStr & OriVal
TempStr = ""
OriVal = ""
Next Cell
Application.ScreenUpdating = True
End Sub