+ Reply to Thread
Results 1 to 6 of 6

SelectionChange event not firing

  1. #1
    Registered User
    Join Date
    01-30-2019
    Location
    Heythuysen, Netherlands
    MS-Off Ver
    Office 2019
    Posts
    6

    Question SelectionChange event not firing

    Hi all,

    First post on the forum, so 'Hi' to you all! I've used your forum in lots of cases to help me address issues in VBA programming, but now I've encountered one that is quite persistent. I'm on Excel 2019 and am looking to create an audit trail for capturing changes to a planning file I manage at work.

    Capture.JPG

    Above is the audit trail I am looking for. The problem I am having is that the "Previous Value" is not captured due to a Worksheet_SelectionChange not firing. Please find the code below that is present in the target worksheet.

    Please Login or Register  to view this content.
    As said previously, the Worksheet_Change event does fire, but the Previous Value is empty as the Worksheet_SelectionChange event does not fire. I've tested and excluded Application.EnableEvents was set to False. Does anyone have any idea where I should be looking?

    Best regards,
    Don

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: SelectionChange event not firing

    I think the event is firing but your variable isn't holding the target value.

    Read this to learn all about variable scope: https://stackoverflow.com/questions/...ariable-in-vba

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: SelectionChange event not firing

    If you change one cell, the PreviousValues will not be an array, and your Change event code won't work. Equally, if you did change more than one value, it will be a 2 dimensional array, not 1D, so your code will fail. You won't know that either way though because you stuck On Error Resume Next at the top of it, so nothing will appear to be wrong.

    Personally, my preference would be to use just the Change event, store the Target.Value in your variable, disable events, then use Application.Undo to remove the changes and then test the old value(s) as appropriate. You can then reinstate the changes and reset events.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    01-30-2019
    Location
    Heythuysen, Netherlands
    MS-Off Ver
    Office 2019
    Posts
    6

    Re: SelectionChange event not firing

    Hi all,

    Thanks for your quick replies. Scoping shouldn't be the issue (as far as I can tell now), as I have declared the PreviousValues outside of the events, so it can be used by both Change and SelectionChange events. I had it working yesterday and it could detect all changes in an array and make note of that in the AuditTrail worksheet, which is a functionality I'd like to preserve as I am often finding myself adjusting multiple cells in the same time (proprietary information, so unable to share). Hoping you can have a look and help me out, thanks again!

    Best regards,
    Don
    Attached Files Attached Files
    Last edited by dfriederichs; 01-30-2019 at 07:43 AM.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: SelectionChange event not firing

    Respectfully, there is no way the code you posted ever worked. Target(c).Value and PreviousValues(c) make no sense at all if c is a Range object, in addition to the errors I mentioned previously.

    You could do something like this:

    Please Login or Register  to view this content.
    Last edited by romperstomper; 01-30-2019 at 08:09 AM.

  6. #6
    Registered User
    Join Date
    01-30-2019
    Location
    Heythuysen, Netherlands
    MS-Off Ver
    Office 2019
    Posts
    6

    Re: SelectionChange event not firing

    Hi Rorya,

    Thank you for looking into the code! I had to switch the PreviousValues and a.Value columns to have the macro insert in the proper column, but other than that it works like a charm!!!

    Best regards,
    Don

+ 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. SelectionChange() Event Stops Firing
    By jo15765 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-21-2017, 09:25 AM
  2. [SOLVED] Userform multipage control - exit event not firing or event order
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 10:23 AM
  3. How to prevent SelectionChange event firing before Change event?
    By franklyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2012, 05:17 AM
  4. [SOLVED] VBA + SelectionChange event
    By HuskerBronco in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-13-2011, 06:36 PM
  5. Worksheet SelectionChange Event
    By mjack003 in forum Excel General
    Replies: 2
    Last Post: 05-08-2006, 03:35 PM
  6. SelectionChange event
    By Kate in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2005, 02:10 PM
  7. SelectionChange event
    By Hayeso in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2005, 11:05 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