Simple Find & Replace code required

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,636
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
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. 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
17,196
Office Version
  1. 365
  2. 2010
Platform
  1. 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,636
Office Version
  1. 2007
Platform
  1. 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
17,196
Office Version
  1. 365
  2. 2010
Platform
  1. Windows

ADVERTISEMENT

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,636
Office Version
  1. 2007
Platform
  1. 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,636
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

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,593
Office Version
  1. 2007
Platform
  1. 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,636
Office Version
  1. 2007
Platform
  1. 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,593
Office Version
  1. 2007
Platform
  1. 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,108,701
Messages
5,524,405
Members
409,575
Latest member
navarrov74

This Week's Hot Topics

Top