+ Reply to Thread
Results 1 to 5 of 5

Excel macro stops after Replace statement

  1. #1
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    2

    Excel macro stops after Replace statement

    Take the following simple macro:

    Please Login or Register  to view this content.
    The macro stops after the Selection.Replace [...] statement; it makes the replacements OK, but stays on range A1:C1 and never selects range A3. I cannot get the macro do to *anything* after the Selection.Replace task. The macro does not show any error; just stops.

    I suspect this is because Excel would normally pop up an info dialog "Excel has completed its search and has made [n] replacements" (on which the user has to click OK), although I do not see this dialog when running the macro. Could this be causing the macro to freeze? Is there a way of suppressing this Replace info dialog from within the macro? I tried Application.DisplayAlerts = False - to no avail.
    Last edited by jean-marc; 08-10-2011 at 03:33 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Excel macro stops after Replace statement

    Hi jean-marc

    Welcome to the Forum....

    Please wrap your code in code tags, before the moderators get you...

    Click here - Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.
    Cheers

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Excel macro stops after Replace statement

    Do you have any other code in the workbook/sheet that may be interfering, such as a Worksheet_SelectionChange event?
    Incidentally, the selection is unnecessary:
    Please Login or Register  to view this content.
    performs the replace without selection.
    Remember what the dormouse said
    Feed your head

  4. #4
    Registered User
    Join Date
    08-10-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Excel macro stops after Replace statement

    Hi romperstomper,

    Prompted by your hint of an interference, I closed down all other spreadsheets I had open (which also contained macros I had previously executed), and it now works fine! Will need to narrow down which is the culprit by trial and error. Any idea how to overcome this problem? Would you view this as a bug? Seems quite legitimate to have several spreadsheets open with previously executed macros, no?

    Thanks for the tip about the Selection. You can see I am not a VBA expert: I usually just record a macro via Excel, then do some tweaking via VBA.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Excel macro stops after Replace statement

    It's not something I've ever heard of or come across myself. If you can narrow down the steps required to cause it, I will file it as a bug with Microsoft.

+ 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