gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 346
- Office Version
- 365
- Platform
- Windows
- Mobile
On sheet 1 is a large table with various fields, including some office names. On sheet 2 is a list of office names I want to be replaced with an empty string. I've created a simple sub to carry this out, but nothing is happening. If I bring of the Find & Replace dialog after running the code, it will show the search term there, and if I try to F&R manually, it can't find anything. However, if I delete the search term and re-type it, then it will work. Any thoughts? Since I'm using wildcards, it seems like it should capture everything in the cell where the search term is present.
Sheet 2 Office Names
Example of Office Names on Sheet 1
VBA Code:
Sub FinderAndReplacer()
Dim sTerm As String
Dim rngA As Range
Dim i As Long
Set rngA = Sheet1.ListObjects(1).DataBodyRange.Cells
Set rngB = Sheet2.Range("C4:C171")
For i = 0 To rngB.Cells.Count - 1
sTerm = rngB.Cells(i + 1, 1).Value
sTerm = "*" & Mid(sTerm, 2, Len(sTerm) - 2) & "*"
rngA.Replace What:=sTerm, Replacement:=""
Next i
End Sub
Sheet 2 Office Names
Example of Office Names on Sheet 1