+ Reply to Thread
Results 1 to 8 of 8

Block Search and Replace

  1. #1
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Block Search and Replace

    Hi

    Does anyone know of a way to search and replace code in VBA for more than one line as I need to change a lot of blocks of code and to do it manually will increase the possibility of errors.

    Many thanks

    Jeff

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Block Search and Replace

    Hi, Possibly "Edit On the VB ToolBar Then "Find" or "Find Next" Or "Replace".
    Mick

  3. #3
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Block Search and Replace

    Hi

    Thanks but the find and replace function only allows for one line of text, e.g. if you select multiple lines only the first line is included.

    The problem is I have a large number of blocks of twenty to thirty lines each and to avoid any errors in the process, would like to find and replace the block of text.

    Regards

    Jeff

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Block Search and Replace

    I don't know of a way, but one could be cheeky if one was so inclined and say that if you have the same large code segment repeated so many times in your code you should have placed it in a seperate sub / function and then used a 'call' to it...
    You could then of course just 'repaired' the one copy of it...

    Lesson learned maybe?
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  5. #5
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Block Search and Replace

    Hi

    I will agree with you on that one and it applies to some but not all of what I want to do and I will look at changing that where it applies.

    However some of the code I wish to change is repeated in other areas, but it is only the code that falls between specific lines of code that I wish to replace so I cannot use a single line replace.

    I was wondering if anyone else has found a solution.

    Thanks

    Jeff

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Block Search and Replace

    Hello Jeff,

    It is possible using RegExp (VBScript Regular Expressions). If you post either your workbook or a sample, I will write the code for you.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Block Search and Replace

    Hi

    Thanks Leith, I have checked it out and think I should be able to manage it now, thanks for the info and the offer.

    Regards

    Jeff

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Block Search and Replace

    Hello Jeff,

    If you have any problems with using RegExp, let me know.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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