+ Reply to Thread
Results 1 to 4 of 4

VBA find and replace using arrays

  1. #1
    Registered User
    Join Date
    10-19-2021
    Location
    Australia
    MS-Off Ver
    365
    Posts
    3

    Question VBA find and replace using arrays

    Hi,

    I would be grateful if someone could point me in the right direction. I am trying to perform a find and replace for multiple words in a Word document. I want to search for example 'Find1', 'Find2', 'Find3' and replace with 'Replace1, 'Replace2', 'Replace3', so that all instances of 'Find1' are replaced with 'Replace1', all instances of 'Find2' are replaced with 'Replace2' and so on. Both arrays have the same number of items so I want to replace in order if that makes sense. Here's my effort so far, however it replaces both 'Find1' and 'Find2' with 'Replace1'.

    Please Login or Register  to view this content.
    Any assistance would be much appreciated.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: VBA find and replace using arrays

    You don't need two loops:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    10-19-2021
    Location
    Australia
    MS-Off Ver
    365
    Posts
    3

    Re: VBA find and replace using arrays

    Thank you very much, this solved it! Much appreciated.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: VBA find and replace using arrays

    You should replace 'Selection' with 'ActiveDocument.Range', otherwise you risk not all instances being replaced.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 03-08-2022, 01:06 AM
  2. Replies: 0
    Last Post: 02-13-2021, 03:32 AM
  3. [SOLVED] VBA to find and replace arrays in specific columns
    By ahsteinb in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-16-2019, 03:13 PM
  4. [SOLVED] Find and replace using arrays
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2017, 08:23 AM
  5. [SOLVED] Replace loops with arrays
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2016, 10:11 AM
  6. [SOLVED] New to arrays-where do I find a good beginners guide to multi dimensional arrays
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-04-2013, 07:44 PM
  7. Find and Replace Arrays
    By s2nguyen in forum Excel General
    Replies: 5
    Last Post: 10-29-2008, 10:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1