Excel VBA to Word string replacement

I have a code snippet that pulls the data from my Excel workbook into an array and then populates the list within a Word document. There are multiple lists within the document and each has a unique placeholder. The code runs perfectly well for 5 out of 6 lists, but for some reason mashes all arrays together into the 2nd list. A snippet of the code below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> ' Loop through each row in ManagerArray
For row = LBound(ManagerArray) To UBound(ManagerArray)
' Replace placeholder with ManagerArray row content
wdoc.Content.Find.Execute FindText:="<<ManagerCriteria>>", ReplaceWith:=ManagerArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(ManagerArray) Then
wdoc.Content.Find.Execute FindText:=ManagerArray(row), ReplaceWith:=ManagerArray(row) & vbCr & "<<ManagerCriteria>>", Replace:=wdReplaceAll
End If
Next row
' Loop through each row in BRArray
For row = LBound(BRArray) To UBound(BRArray)
' Replace placeholder with BRArray row content
wdoc.Content.Find.Execute FindText:="<<BRCriteria>>", ReplaceWith:=BRArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(BRArray) Then
wdoc.Content.Find.Execute FindText:=BRArray(row), ReplaceWith:=BRArray(row) & vbCr & "<<BRCriteria>>", Replace:=wdReplaceAll
End If
Next row
' Loop through each row in AIMArray
For row = LBound(AIMArray) To UBound(AIMArray)
' Replace placeholder with AIMArray row content
wdoc.Content.Find.Execute FindText:="<<AIMCriteria>>", ReplaceWith:=AIMArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(AIMArray) Then
wdoc.Content.Find.Execute FindText:=AIMArray(row), ReplaceWith:=AIMArray(row) & vbCr & "<<AIMCriteria>>", Replace:=wdReplaceAll
End If
Next row
' Loop through each row in EISArray
For row = LBound(EISArray) To UBound(EISArray)
' Replace placeholder with EISArray row content
wdoc.Content.Find.Execute FindText:="<<EISCriteria>>", ReplaceWith:=EISArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(EISArray) Then
wdoc.Content.Find.Execute FindText:=EISArray(row), ReplaceWith:=EISArray(row) & vbCr & "<<EISCriteria>>", Replace:=wdReplaceAll
End If
Next row
' Loop through each row in SEISArray
For row = LBound(SEISArray) To UBound(SEISArray)
' Replace placeholder with SEISArray row content
wdoc.Content.Find.Execute FindText:="<<SEISCriteria>>", ReplaceWith:=SEISArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(SEISArray) Then
wdoc.Content.Find.Execute FindText:=SEISArray(row), ReplaceWith:=SEISArray(row) & vbCr & "<<SEISCriteria>>", Replace:=wdReplaceAll
End If
Next row
' Loop through each row in VCTArray
For row = LBound(VCTArray) To UBound(VCTArray)
' Replace placeholder with VCTArray row content
wdoc.Content.Find.Execute FindText:="<<VCTCriteria>>", ReplaceWith:=VCTArray(row), Replace:=wdReplaceAll
' Insert new line and placeholder after the replaced content if it's not the last row
If row < UBound(VCTArray) Then
wdoc.Content.Find.Execute FindText:=VCTArray(row), ReplaceWith:=VCTArray(row) & vbCr & "<<VCTCriteria>>", Replace:=wdReplaceAll
End If
Next row
</code>
<code> ' Loop through each row in ManagerArray For row = LBound(ManagerArray) To UBound(ManagerArray) ' Replace placeholder with ManagerArray row content wdoc.Content.Find.Execute FindText:="<<ManagerCriteria>>", ReplaceWith:=ManagerArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(ManagerArray) Then wdoc.Content.Find.Execute FindText:=ManagerArray(row), ReplaceWith:=ManagerArray(row) & vbCr & "<<ManagerCriteria>>", Replace:=wdReplaceAll End If Next row ' Loop through each row in BRArray For row = LBound(BRArray) To UBound(BRArray) ' Replace placeholder with BRArray row content wdoc.Content.Find.Execute FindText:="<<BRCriteria>>", ReplaceWith:=BRArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(BRArray) Then wdoc.Content.Find.Execute FindText:=BRArray(row), ReplaceWith:=BRArray(row) & vbCr & "<<BRCriteria>>", Replace:=wdReplaceAll End If Next row ' Loop through each row in AIMArray For row = LBound(AIMArray) To UBound(AIMArray) ' Replace placeholder with AIMArray row content wdoc.Content.Find.Execute FindText:="<<AIMCriteria>>", ReplaceWith:=AIMArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(AIMArray) Then wdoc.Content.Find.Execute FindText:=AIMArray(row), ReplaceWith:=AIMArray(row) & vbCr & "<<AIMCriteria>>", Replace:=wdReplaceAll End If Next row ' Loop through each row in EISArray For row = LBound(EISArray) To UBound(EISArray) ' Replace placeholder with EISArray row content wdoc.Content.Find.Execute FindText:="<<EISCriteria>>", ReplaceWith:=EISArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(EISArray) Then wdoc.Content.Find.Execute FindText:=EISArray(row), ReplaceWith:=EISArray(row) & vbCr & "<<EISCriteria>>", Replace:=wdReplaceAll End If Next row ' Loop through each row in SEISArray For row = LBound(SEISArray) To UBound(SEISArray) ' Replace placeholder with SEISArray row content wdoc.Content.Find.Execute FindText:="<<SEISCriteria>>", ReplaceWith:=SEISArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(SEISArray) Then wdoc.Content.Find.Execute FindText:=SEISArray(row), ReplaceWith:=SEISArray(row) & vbCr & "<<SEISCriteria>>", Replace:=wdReplaceAll End If Next row ' Loop through each row in VCTArray For row = LBound(VCTArray) To UBound(VCTArray) ' Replace placeholder with VCTArray row content wdoc.Content.Find.Execute FindText:="<<VCTCriteria>>", ReplaceWith:=VCTArray(row), Replace:=wdReplaceAll ' Insert new line and placeholder after the replaced content if it's not the last row If row < UBound(VCTArray) Then wdoc.Content.Find.Execute FindText:=VCTArray(row), ReplaceWith:=VCTArray(row) & vbCr & "<<VCTCriteria>>", Replace:=wdReplaceAll End If Next row </code>
    ' Loop through each row in ManagerArray
    For row = LBound(ManagerArray) To UBound(ManagerArray)
        ' Replace placeholder with ManagerArray row content
        wdoc.Content.Find.Execute FindText:="<<ManagerCriteria>>", ReplaceWith:=ManagerArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(ManagerArray) Then
            wdoc.Content.Find.Execute FindText:=ManagerArray(row), ReplaceWith:=ManagerArray(row) & vbCr & "<<ManagerCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

    
    ' Loop through each row in BRArray
    For row = LBound(BRArray) To UBound(BRArray)
        ' Replace placeholder with BRArray row content
        wdoc.Content.Find.Execute FindText:="<<BRCriteria>>", ReplaceWith:=BRArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(BRArray) Then
            wdoc.Content.Find.Execute FindText:=BRArray(row), ReplaceWith:=BRArray(row) & vbCr & "<<BRCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

    
    ' Loop through each row in AIMArray
    For row = LBound(AIMArray) To UBound(AIMArray)
        ' Replace placeholder with AIMArray row content
        wdoc.Content.Find.Execute FindText:="<<AIMCriteria>>", ReplaceWith:=AIMArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(AIMArray) Then
            wdoc.Content.Find.Execute FindText:=AIMArray(row), ReplaceWith:=AIMArray(row) & vbCr & "<<AIMCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

    
    ' Loop through each row in EISArray
    For row = LBound(EISArray) To UBound(EISArray)
        ' Replace placeholder with EISArray row content
        wdoc.Content.Find.Execute FindText:="<<EISCriteria>>", ReplaceWith:=EISArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(EISArray) Then
            wdoc.Content.Find.Execute FindText:=EISArray(row), ReplaceWith:=EISArray(row) & vbCr & "<<EISCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

    
    ' Loop through each row in SEISArray
    For row = LBound(SEISArray) To UBound(SEISArray)
        ' Replace placeholder with SEISArray row content
        wdoc.Content.Find.Execute FindText:="<<SEISCriteria>>", ReplaceWith:=SEISArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(SEISArray) Then
            wdoc.Content.Find.Execute FindText:=SEISArray(row), ReplaceWith:=SEISArray(row) & vbCr & "<<SEISCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

    
    ' Loop through each row in VCTArray
    For row = LBound(VCTArray) To UBound(VCTArray)
        ' Replace placeholder with VCTArray row content
        wdoc.Content.Find.Execute FindText:="<<VCTCriteria>>", ReplaceWith:=VCTArray(row), Replace:=wdReplaceAll
    
        ' Insert new line and placeholder after the replaced content if it's not the last row
        If row < UBound(VCTArray) Then
            wdoc.Content.Find.Execute FindText:=VCTArray(row), ReplaceWith:=VCTArray(row) & vbCr & "<<VCTCriteria>>", Replace:=wdReplaceAll
        End If
    Next row

The codes are all the same, except for the placeholder and corresponding array. The issue occurs with the BRArray replacement – I have debug printed it and it is showing the correct list in the immediate window. If I move any of the following arrays around, it will always happen to whatever replacement happens 2nd in the code. Any ideas on what could the issue be?

Tried separating the replacement part into a separate subroutine, but this did not solve the issue.

New contributor

Van Li is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật