nicolas877
New Member
- Joined
- Jan 15, 2022
- Messages
- 13
- Office Version
- 2019
- Platform
- Windows
Hi forum, i need a vba code to replace text following multuple criteria in a sheet like this
Before
Date Name
Week 1 Tom
Week 1 Tom
Week 2 kate
Week 4 Tom
To
Date Name
Week 1 Tom Hanks
Week 1 Tom Hanks
Week 2 kate Smith
Week 4 Tom Miller
Using this key
Week 1 Tom Hanks
Week 2 Kate Smith
Week 4 Tom Miller
The real sheet has like 15000 diferents rows and multiple names/dates, i tried using this code but only works with one condition (like replace Tom with Tom Hanks, but i also the week criteria)
Before
Date Name
Week 1 Tom
Week 1 Tom
Week 2 kate
Week 4 Tom
To
Date Name
Week 1 Tom Hanks
Week 1 Tom Hanks
Week 2 kate Smith
Week 4 Tom Miller
Using this key
Week 1 Tom Hanks
Week 2 Kate Smith
Week 4 Tom Miller
The real sheet has like 15000 diferents rows and multiple names/dates, i tried using this code but only works with one condition (like replace Tom with Tom Hanks, but i also the week criteria)
VBA Code:
Sub MultiFindNReplace()
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value, Lookat:=xlWhole
Next
Application.ScreenUpdating = True
End Sub