Good day folks,





I am doing search and replacement between sets of ranges that I have put between 2 placeholders.

I have put them in an array.

Each set has a different search and replacement to happen.

The problem is it is replacing the same for both sets.






 Sub CSET_Forum()
    

    Dim oRng As Range
    Dim oRng2 As Range
    Dim lngIndex As Long
    Dim k As Variant
    Dim Array_Terms             'dimmed as variant
    

    'Array Terms
    'Place holder 1      =  Term[0]
    'Placeholder  2      =  Term[1]
    'Search              =  Term[2]
    'Replace             =  Term[3]
    '---------------------------------------------------------------------
    
   

   
    Array_Terms = Array(Array("[A1]", "[A2]", "Apple", "11111"), Array("[B3]", "[B4]", "Apple", "22222"))
    
     
    
    k = 0
    For lngIndex = LBound(Array_Terms) To UBound(Array_Terms)
    
    
    Set oRng = ActiveDocument.Range
    With oRng.Find
    
    'Find the Ranges between the 2 Placeholders
    Do While .Execute(FindText:=Array_Terms(k)(0) & "*" & Array_Terms(k)(1), MatchWildcards:=True)
    
    
    
    '------------------------------------------
    ' Each Range  - Do the Search and Replacements
    Set oRng2 = oRng
    With oRng2.Find
    
    'Search and Replace
    Do While .Execute(FindText:=Array_Terms(k)(2), MatchWholeWord:=True)
    
    oRng2.Text = Array_Terms(k)(3)
    
    
    '.Wrap = wdFindStop
    
    oRng2.Collapse 0
    

    Loop
    End With
    Set oRng2 = Nothing
    '------------------------------------------


   
    Loop
    End With
    k = k + 1
    Next lngIndex

lbl_Exit:
    Exit Sub
End Sub





I know I may not have set my ranges correctly and my loop may be not correct. I added an inner loop but that still didn’t work.

Please do help and advise

Thank you for you time.