+ Reply to Thread
Results 1 to 8 of 8

Selection change macro

  1. #1
    Registered User
    Join Date
    08-17-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    35

    Selection change macro

    Hey all
    I'm trying to write a macro that will run an advanced filter when the user changes the value of a drop down list. I've got the following but it is not working. I'm new to writing scripts so please let me know what I am doing wrong. The advanced filter part should be working as that was a recorded macro from doing the filter which was successful.
    Thanks
    Alan

    Please Login or Register  to view this content.
    Last edited by alanb1976; 08-17-2011 at 11:31 AM.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Selection change macro

    Hi Alan,

    Please can you edit your post and add code tags around the code? Explained under point #3 here.

    Once done, I'll explain what's going wrong with your code.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    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
    44,521

    Re: Selection change macro

    Please re-read the forum rules and apply CODE tags to your code sample.

    However, you probably need Change rather than SelectionChange.

    The Target in SelectionChange is the cell you have moved to, not the cell you have changed.

    Regards
    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


  4. #4
    Registered User
    Join Date
    08-17-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Selection change macro

    Apologies.... edited.

    The cell that gets changed is B2. I wasn't sure on how to specify that as there are numerous times that 'range' gets mentioned

  5. #5
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Selection change macro

    Thanks for adding code tags.

    As TM Shucks mentioned, you're trapping the wrong event handler. However, there may also be an issue with the ranges because they are unqualified in the code. Please can you attach your workbook to the thread, or clarify exactly which sheet the CriteriaRange and CopyToRange sit on, and which Sheet contains the data validation Dropdown list?

  6. #6
    Registered User
    Join Date
    08-17-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Selection change macro

    Thanks.
    I have attached the workbook but it's still a mess and had to delete the data due to it containing sensitive company info.
    As you can see, there is a 'test' sheet where I want the user to be able to select their name reference from the drop down list (B2). Once done I want it to automatically update filters to display all actions associated with them. At the moment I was just testing with the 'General Actions'. So, from 'test' they would select their name and it would update the 'test' sheet with info from the 'General Actions' sheet that corresponds to the "Owner" column. I hope I am explaining properly.
    I am basically looking for a statement like 'if B2 changes, run the following advanced filter'.
    Thanks for the help.
    Alan
    Attached Files Attached Files

  7. #7
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Selection change macro

    Okay, the code at the moment is sitting in module1, which is the wrong place. It needs to sit in the Sheet1 module. Also, you only want the advanced filter to be called when B2 is changed, not other cells.

    So, your revised code (in Sheet1) would be:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-17-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    35

    Re: Selection change macro

    Thanks. That was perfect!
    Just 1 follow on question if you don't mind. Is there a way of updating a cell shown from the filtered results and having it update the related cell in the other worksheet automatically?
    Thanks again
    alan

+ 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