Consulting

Results 1 to 4 of 4

Thread: Find And Replace with Increment Number Excel VBA

  1. #1
    VBAX Newbie
    Joined
    Jan 2021
    Posts
    3
    Location

    Post Find And Replace with Increment Number Excel VBA

    Hello All,

    is there any Excel VBA code that should help me for find and replace? example i want to find "STD" in excel Sheet and then Replace it With "Division 1" after that next find "STD" and it would replace to "Division 2" and so on... for each STD find the replacement would be increment the Division Number Like "Division 3", "Division 4", "Division 5" and so on... until the last STD find. Please find the attachment for the refrence.
    Attached Images Attached Images

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PHP Code:
    Sub vbax_68341_find_replace_increment_multiple_occurrences_v()

        
    Dim LastCell As RangeFoundCell As Range
        Dim FirstAddress 
    As String
        Dim Counter 
    As Long

        On Error Resume Next

        With ActiveSheet
    .UsedRange
            Set LastCell 
    = .Cells(.Cells.Count)
            
    Set FoundCell = .Find(What:="STD"After:=LastCellLookIn:=xlValuesLookAt:=xlPartSearchOrder:=xlByColumnsSearchDirection:=xlNext)
            If 
    Not FoundCell Is Nothing Then
                FirstAddress 
    FoundCell.Address
                Counter 
    1
                FoundCell
    .Value "Division " Counter
                
    Do
                    
    Set FoundCell = .FindNext(FoundCell)
                    
    Counter Counter 1
                    FoundCell
    .Value "Division " Counter
                Loop Until FoundCell
    .Address FirstAddress
            End 
    If
        
    End With

    End Sub 
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Newbie
    Joined
    Jan 2021
    Posts
    3
    Location
    Thank You So Much Bro. You Don't Know How Much you Help Me... Love You A Lot.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
      On error Resume Next
      n = 1
    
      Do
        Cells.Find("STD") = "snb_" & n
        n = n + 1
      Loop Until Err.Number <> 0
    End Sub

Posting Permissions

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