Simple Find & Replace code required

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,376
Office Version
2007
Platform
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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
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
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,933
Office Version
2010
Platform
Windows
Code:
Sub ReplacePartNumber()
With Sheets("HONDA LIST")
    .Range("E:E").Replace "08E56-CAT-888", " 08E56-CAT-888-02", lookat:=xlPart
End With
End Sub
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,376
Office Version
2007
Platform
Windows
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
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,933
Office Version
2010
Platform
Windows
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:

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,376
Office Version
2007
Platform
Windows
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
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,376
Office Version
2007
Platform
Windows
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
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
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,376
Office Version
2007
Platform
Windows
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 ???
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
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]
 

Watch MrExcel Video

Forum statistics

Threads
1,101,851
Messages
5,483,311
Members
407,393
Latest member
GeorgeBrown

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top