Highlight Range Col B - Replace String 'Test' VBA

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
Selected range is in Col B..

1) Find all instances of the 'string 'Test'
2) replace the string 'Test" with the value in Col C, same row for each instance found


Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is this a case-sensitive search? That is, should the string 'test' also be replaced with the adjacent value?

Will the string 'Test' ever occur more than once in a single cell?

Can you confirm that you are looking for the string 'Test' as you stated not the word 'Test'? That is the red text here would get replaced "Testing proved easy"
 
Upvote 0
Is this a case-sensitive search? That is, should the string 'test' also be replaced with the adjacent value?

Will the string 'Test' ever occur more than once in a single cell?

Can you confirm that you are looking for the string 'Test' as you stated not the word 'Test'? That is the red text here would get replaced "Testing proved easy"
Hi, not case sensitive, only 1x per cell, and it is a string
 
Upvote 0
Try this with a copy of your data.

VBA Code:
Sub Replace_String()
  Dim a As Variant
  Dim i As Long
  
  With Selection
    a = .Resize(, 2).Value
    For i = 1 To UBound(a)
      a(i, 1) = Replace(a(i, 1), "test", a(i, 2), 1, -1, 1)
    Next i
    .Value = a
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top