Simple Find & Replace code required

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Evening,

For some reason a certain part number in my worksheet doesnt get entered correctly.

So can somebody wright me a simple code to find this number in a specific column & once found replace it with the correct number.

This is the infro that you will require to assist you.

Worksheet is called HONDA LIST

Will always be looking in column E

Part number to FIND is 08E56-CAT-888

Replace it with part number 08E56-CAT-888-02

Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this

Code:
Sub Macro3()
    Sheets("HONDA LIST").Range("E:E").Replace _
        What:="08E56-CAT-888", Replacement:="08E56-CAT-888-02", _
        LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
        SearchFormat:=False, ReplaceFormat:=False
End Sub
 
Upvote 0
Code:
Sub ReplacePartNumber()
With Sheets("HONDA LIST")
    .Range("E:E").Replace "08E56-CAT-888", " 08E56-CAT-888-02", lookat:=xlPart
End With
End Sub
 
Upvote 0
Hi,

This worked great for me.

Can you advise where i need to check so i can add it to run upon worksheet

Code:
Sub ReplaceCat1Number()With Sheets("HONDA LIST")
    .Range("E:E").Replace "08E56-CAT-888", " 08E56-CAT-888-02", lookat:=xlPart
End With
End Sub
Thinking about it probaly better to run it when workbook ope.

I have this in place already so can we also apply the code also shown above.
Thanks

Code:
Private Sub Workbook_Open()   With Worksheets("HONDA LIST")
    .Activate
    Range("A13").Select
    ActiveWindow.ScrollRow = 13
   End With
End Sub
 
Upvote 0
Maybe this:
Code:
Private Sub Workbook_Open()
With Worksheets("HONDA LIST")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart
    .Range("A13").Select
    ActiveWindow.ScrollRow = 13
End With
End Sub
 
Last edited:
Upvote 0
Many thanks that worked.

Just need to finish with these last 2 additions.

Bloew is what i have so far,you will see that i have added the horizontal alignment as when the value is altered the value is "Align Text Left" & it needs to be "Centered" , unfortuneatly the error message said it wasnt supported.

Ive also shuffled around another worksheet which uses the same part number so can we also add that sheet into the code for it to do the same.
I made sure to also put it in column E
Thise additional sheet is called HONDA LIST

Code:
Private Sub Workbook_Open()With Worksheets("HONDA SHEET")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart,
    .HorizontalAlignment = xlGeneral
    .Range("A13").Select
    ActiveWindow.ScrollRow = 13
End With
End Sub

Thanks for your time
 
Upvote 0
Nearly there.

Just need to sort alignment now.

Code:
Private Sub Workbook_Open()With Worksheets("HONDA LIST")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart
End With
With Worksheets("HONDA SHEET")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart
    .Range("A13").Select
    ActiveWindow.ScrollRow = 13
End With
End Sub
 
Upvote 0
Nearly there.

Just need to sort alignment now.

Code:
Private Sub Workbook_Open()
With Worksheets("HONDA LIST")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart
End With
With Worksheets("HONDA SHEET")
    .Activate
    .Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=xlPart
[COLOR=#ff0000]    .Range("E:E").HorizontalAlignment = xlCenter[/COLOR]
    .Range("A13").Select
    ActiveWindow.ScrollRow = 13
End With
End Sub

Try
 
Upvote 0
Many thanks that sorted it
BUT
I see a problem.

This is my work process.

Part number CURRENTLY in cell 08E56-CAT-888
I open workbood & the code does its work,now i see the part number as 08E56-CAT-888-02 "perfect"
When i close the workbook and open it again i see the code has added another 02 on the end
So what was 08E56-CAT-888-02 is now 08E56-CAT-888-02-02

Each time i open the workbook 02 is added every time.
Im going to end up with 08E56-CAT-888-02-02-02-02-02-02 soon...

Why does this happen if the code should only be looking for 08E56-CAT-888 ???
 
Upvote 0
Many thanks that sorted it
BUT
I see a problem.

This is my work process.

Part number CURRENTLY in cell 08E56-CAT-888
I open workbood & the code does its work,now i see the part number as 08E56-CAT-888-02 "perfect"
When i close the workbook and open it again i see the code has added another 02 on the end
So what was 08E56-CAT-888-02 is now 08E56-CAT-888-02-02

Each time i open the workbook 02 is added every time.
Im going to end up with 08E56-CAT-888-02-02-02-02-02-02 soon...

Why does this happen if the code should only be looking for 08E56-CAT-888 ???

If in the cell you only have this:

"08E56-CAT-888"


Then change to this:

Code:
.Range("E:E").Replace "08E56-CAT-888", "08E56-CAT-888-02", lookat:=[COLOR=#0000ff]xlWhole[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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