Macro to find & replace Text

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have written to find text and then replace the text beginning with EA04- folowed by the original text


Eg of raw data

PO 1272 Northern 04 - DOC 3974


Data should like like this after running macro


EA04-PO 1272 Northern 04 - DOC 3974



Code:
 Sub findPlace()

    For X = 1 To Cells(Rows.Count, "A").End(xlUp).Row
        If InStr(1, Cells(X, 1).Value, "Northern", vbTextCompare) > 0 Then
            Cells(X, 1) = "EA04-&"
           
        End If
        
    Next X


End Sub

Your assistance regarding the above is most appreciated
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Sub findPlace()
Dim X As Long
For X = 1 To Cells(Rows.Count, "A").End(xlUp).Row
    If InStr(1, Cells(X, 1).Value, "Northern", vbTextCompare) > 0 Then
        Cells(X, 1).Value = "EA04-" & Cells(X, 1).Value
    End If
Next X
End Sub
 
Upvote 0
Hi Peter

Thanks for the help, much appreciated

Howard
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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