Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Simple Find & Replace code required

  1. #1
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,478
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Simple Find & Replace code required

    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
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,236
    Post Thanks / Like
    Mentioned
    70 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Simple Find & Replace code required

    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
    Regards Dante Amor

  3. #3
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,482
    Post Thanks / Like
    Mentioned
    37 Post(s)
    Tagged
    8 Thread(s)

    Default Re: Simple Find & Replace code required

    Code:
    Sub ReplacePartNumber()
    With Sheets("HONDA LIST")
        .Range("E:E").Replace "08E56-CAT-888", " 08E56-CAT-888-02", lookat:=xlPart
    End With
    End Sub
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  4. #4
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,478
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Simple Find & Replace code required

    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
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  5. #5
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,482
    Post Thanks / Like
    Mentioned
    37 Post(s)
    Tagged
    8 Thread(s)

    Default Re: Simple Find & Replace code required

    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 by JoeMo; Jun 18th, 2019 at 03:53 PM.
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  6. #6
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,478
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Simple Find & Replace code required

    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
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  7. #7
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,478
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Simple Find & Replace code required

    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
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  8. #8
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,236
    Post Thanks / Like
    Mentioned
    70 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Simple Find & Replace code required

    Quote Originally Posted by ipbr21054 View Post
    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("E:E").HorizontalAlignment = xlCenter
        .Range("A13").Select
        ActiveWindow.ScrollRow = 13
    End With
    End Sub
    Try
    Regards Dante Amor

  9. #9
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,478
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Simple Find & Replace code required

    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 ???
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  10. #10
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,236
    Post Thanks / Like
    Mentioned
    70 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Simple Find & Replace code required

    Quote Originally Posted by ipbr21054 View Post
    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:=xlWhole
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •