Simple Find & Replace code required

ipbr21054

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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,563
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
17,059
Office Version
365, 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,542
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
17,059
Office Version
365, 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,542
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,542
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,563
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,542
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,563
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]
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,014
Messages
5,508,796
Members
408,694
Latest member
LightBright

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top