+ Reply to Thread
Results 1 to 6 of 6

VBA Macro - prompt confirmation message before editing - restore initial formula if no

  1. #1
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    VBA Macro - prompt confirmation message before editing - restore initial formula if no

    Hi All,
    I have an excel sheet with a column that is populated with formulas. I'm trying to set up a macro which prompt a confirmation question when someone try to modify the cell with other values.
    If the answer is Yes, the new value is entered, if not, I'd like to restore the original formula. I figured out from a previous thread in this forum this piece of code. However, after clicking no, the formula is substituted by a value. Any Idea about how I can edit this code to restore the original formula rather than its value?

    thanks in advance

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,482

    Re: VBA Macro - prompt confirmation message before editing - restore initial formula if no

    In your Selection Change Event handler, you pick up the current value. You need to change that to get the formula instead.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8
    Quote Originally Posted by TMS View Post
    In your Selection Change Event handler, you pick up the current value. You need to change that to get the formula instead.
    Thank you Thread, I now figured out, and everything works fine!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,482

    Re: VBA Macro - prompt confirmation message before editing - restore initial formula if no

    You're welcome.

    Thread???





    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: VBA Macro - prompt confirmation message before editing - restore initial formula if no

    Personally I would use the change event. Have it store the new value in a variable, disable events, then have it perform an undo which reverts to old value, then prompt the user and set the value of the cell to the desired value by either leaving it as the old or replacing the old with the stored new value and lastly enabling events again.

    In the above a couple things to consider. Check that the change is on a single cell and that potentially if its within the range you want to check for. You may also consider checking if it was originally blank, just skip the event. As a matter of preference you can eval the opposite (had something and new entry is blank (either let it be blank and skip or still prompt).

    This method can greatly reduce the number of times you trigger an event/code.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  6. #6
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA Macro - prompt confirmation message before editing - restore initial formula if no

    Done TMS, thanks

+ 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. Confirmation message AFTER runing a macro
    By lofgren in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2017, 07:23 AM
  2. Confirmation prompt to edit non-empty cell (excluding those with formula)
    By Ljung in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2016, 01:48 AM
  3. macro to avoid prompt message when opeing in readonly
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2014, 08:33 PM
  4. [SOLVED] Message Box Asking For Confirmation
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2014, 04:15 AM
  5. [SOLVED] Compare cell values of different Workbooks and prompt message using macro
    By jericlapuz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2012, 03:42 AM
  6. Confirmation Prompt
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2011, 04:01 PM
  7. Code for Pop-up Message Box with Confirmation
    By macky1730 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2009, 07:31 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