ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Tidy up multiple find and replace code (https://www.excelbanter.com/excel-worksheet-functions/226779-tidy-up-multiple-find-replace-code.html)

PSM[_10_]

Tidy up multiple find and replace code
 

How can I tidy up this code as it goes on for 50+ searches ?


' Update_C5&Mgr (Select Columns)
Range("A:B").Select
Range(Selection, Selection.End(xlDown)).Select

' Update_C5 (Column A)
Selection.Replace What:="*01", _
Replacement:="01", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*07", _
Replacement:="07", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*08", _
Replacement:="08", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*09", _
Replacement:="09", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False




--
PSM

joel

Tidy up multiple find and replace code
 
ReplaceStr = Array("01,"07","08","09")

' Update_C5&Mgr (Select Columns)
Range("A:B").Select
Range(Selection, Selection.End(xlDown)).Select

for each Num in ReplaceStr
Selection.Replace _
What:="*" & Num, _
Replacement:=Num, _
LookAt:=xlPart

next Num



"PSM" wrote:


How can I tidy up this code as it goes on for 50+ searches ?


' Update_C5&Mgr (Select Columns)
Range("A:B").Select
Range(Selection, Selection.End(xlDown)).Select

' Update_C5 (Column A)
Selection.Replace What:="*01", _
Replacement:="01", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*07", _
Replacement:="07", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*08", _
Replacement:="08", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*09", _
Replacement:="09", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False




--
PSM


Don Guillett

Tidy up multiple find and replace code
 
Should be pretty easy. It would help if you post some of the data


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"PSM" wrote in message
...

How can I tidy up this code as it goes on for 50+ searches ?


' Update_C5&Mgr (Select Columns)
Range("A:B").Select
Range(Selection, Selection.End(xlDown)).Select

' Update_C5 (Column A)
Selection.Replace What:="*01", _
Replacement:="01", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*07", _
Replacement:="07", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*08", _
Replacement:="08", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="*09", _
Replacement:="09", LookAt:=xlPart, SearchOrder:=xlByRows,
MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False




--
PSM




All times are GMT +1. The time now is 07:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com