+ Reply to Thread
Results 1 to 5 of 5

Worksheet Change Event - Save file after tenth change

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Worksheet Change Event - Save file after tenth change

    Hi all

    Is there a way in vba to delay a worksheet change event by a number and only fire "ActiveWorkbook.Save" after the tenth change, rather than every change.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Worksheet Change Event - Save file after tenth change

    Add a Static variable to the Change procedure. Increment it every change and Save when it reaches 10 or a multiple of.

    Basic information only - you need to understand what these are and how they work - have a read of the link.

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Worksheet Change Event - Save file after tenth change

    Thanks Cytop but that lost me a bit - went with this while I work out haw to reference the static variable
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Worksheet Change Event - Save file after tenth change

    Confused... why put the code in the Selection_Change event when you mentioned the Change event earlier? As coded the workbook will be saved after every 10th selection of any cell.

    Never mind - to save after every 10 changes
    Please Login or Register  to view this content.
    The difference between
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    is that NumChanges will be destroyed when the procedure exists when it is simply Dim'ed so it will never get to 10. Declaring it as Static preserves the value after the procedure exists.

    Essentially you have done the same thing by storing the value in a worksheet, but why add the complication of interacting with a worksheet when you can simply use a static variable that's tucked away somewhere safe and can't be changed accidentally by other procedures or by the user simply clearing cell F10...

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Worksheet Change Event - Save file after tenth change

    @Cytop
    I had just noticed that the sheet code defaulted to Selection_Change so your response was timely and much appreciated. Hopefully this will assist a user who has no concept of saving his changes until days end lol

+ 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. Worksheet change event 'giving msg of save the changes or not'
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2017, 04:37 AM
  2. Worksheet change event with multiple column cell value change
    By borgyang in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2015, 11:53 AM
  3. [SOLVED] How to prevent worksheet change invoking System X Control change event
    By dmw2014 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-13-2014, 10:35 PM
  4. Worksheet Change event ignore change event
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2011, 12:29 PM
  5. Worksheet Change Event-change the range in my VBA
    By systemx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2006, 05:00 AM
  6. [SOLVED] Cell value change to trigger macro (worksheet change event?)
    By Neil Goldwasser in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2006, 10:00 AM
  7. [SOLVED] Worksheet Change Event-change event to trigger
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2005, 06:05 PM

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