+ Reply to Thread
Results 1 to 10 of 10

Data validation runs worksheet event twice

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Data validation runs worksheet event twice

    Hi,

    i am using DV list:
    Screenshot_16.png

    and i have also worksheet change event:

    Please Login or Register  to view this content.
    This is ok.

    But when you will input into B2 number for example 5 and DV list will show error, worksheet change event will go twice.
    Once for your try to input 5 and second time for returning back (in this case to allowed by DV number 2) after canceling new input.

    How can i solve the issue?
    Please help,
    Jacek
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 04-09-2019 at 07:29 AM. Reason: Changed title to something more explicit

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Data validation runs worksheet event twice

    Hi
    as not everybody is supposed to understand acronyms, it is best to be more explicit in your thread title.
    I changed the DV to "data validation" for you in your thread title.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Data validation runs worksheet event twice

    Thank you Pepe,

    Jacek

  4. #4
    Registered User
    Join Date
    11-06-2012
    Location
    Texas
    MS-Off Ver
    O365
    Posts
    27

    Re: Data validation runs worksheet event twice

    Any change to a worksheet triggers the Worksheet_Change event. This means your code runs the first time when you change the cell, then runs again when the code changes the cell. To prevent this, you need to disable worksheet events at the beginning of your code, then enable events after your code runs.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Data validation runs worksheet event twice

    Thank you Daishiknyte,

    ok but it has to be workaround for this.
    Why to loop twice if DV is wrong and throwing error?

    Maybe i should add function to check if data is correct for DV?

    Best,
    Jacek

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Data validation runs worksheet event twice

    Anyone?

    Jacek

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Data validation runs worksheet event twice

    Please remember that those who help here do so voluntarily and of their own goodwill. They live in many different time zones and many will be out at work right now if they are not asleep on the other side of the globe. This is not a paid 'service': members will help when they are ready and able to do so, and not 'on demand'. Please do not try to put pressure of time on anyone here: if you get the help you need today, that's fine, but you really should not count on it. Thanks for your understanding and patience.

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Data validation runs worksheet event twice

    This code pop up msg box only when the value of B2 is changed. If there is no change in value no popup.
    Code for worksheet event
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Data validation runs worksheet event twice

    o wow great code thank you very much!

    Jacek

  10. #10
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Data validation runs worksheet event twice

    Thanks for feed back.

+ 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. Macro that runs on the SaveAs (PDF) event and not the Save event
    By Doug-M in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2019, 02:07 PM
  2. [SOLVED] Userform runs Initialize sub @ beginning of textbox AfterUpdate event w/out being called
    By chirp08 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-18-2016, 01:02 PM
  3. [SOLVED] Double click event runs twice ?
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-18-2014, 06:53 AM
  4. [SOLVED] Event macro runs in wrong workbook/doesn't work properly
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2012, 11:28 AM
  5. [Solved] Workbook_open event runs before Workbook is open.
    By PGSmick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2012, 04:14 AM
  6. Refining when a worksheet_Change event runs with perhaps ISodd or similar
    By Wobbles in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-19-2011, 09:06 AM
  7. Replies: 5
    Last Post: 06-23-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