VBA learner ITG
Active Member
- Joined
- Apr 18, 2017
- Messages
- 272
- Office Version
- 365
- Platform
- Windows
- MacOS
Hi all,
I need your advice as I cannot seem to amend the code to ignore words that are part of a text string.
For Example:
So that it finds the WHOLE WORD "IL" ONLY??? I want it to replace IL, but it's replacing letters from names like, Bill, for example.
I have tried amending this partof the code to the below and it doesnt work.
My Original code below:
I need your advice as I cannot seem to amend the code to ignore words that are part of a text string.
For Example:
So that it finds the WHOLE WORD "IL" ONLY??? I want it to replace IL, but it's replacing letters from names like, Bill, for example.
I have tried amending this partof the code to the below and it doesnt work.
VBA Code:
LookAt:=xlPart to LookAt:=xlWhole.
My Original code below:
VBA Code:
Sub btn_find_replace_Click()
Dim wb As Workbook
Dim ws As Worksheet
Dim ws_client As Worksheet
Dim tbl As ListObject
Dim lrow As Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("MAIN BRIEF")
Set ws_client = wb.Sheets("CLIENT_FACING")
Set tbl = ws_client.ListObjects("Table1")
For Each lrow In tbl.ListColumns(1).DataBodyRange.Rows
find_str = lrow.Offset(0, 0)
rep_str = lrow.Offset(0, 1)
ws.Cells.Replace what:=find_str, Replacement:=rep_str, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next lrow
Set tbl = Nothing
Set ws = Nothing
Set ws_client = Nothing
Set wb = Nothing
End Sub