+ Reply to Thread
Results 1 to 10 of 10

VBA Code based on Drop down selection

  1. #1
    Registered User
    Join Date
    07-28-2015
    Location
    London, England
    MS-Off Ver
    2011 For Mac
    Posts
    6

    VBA Code based on Drop down selection

    Hello All,

    I am sure this is very simple but it is something I cannot get my head around!

    I have one dropdown box, which is built through Data Validation. This list has two options, YES and NO. If YES is selected then I want it to open another document stored on a shared drive. IF NO is selected then nothing should happen.

    At the moment I have: (MsgBox is for testing - but it doesn't work)

    Please Login or Register  to view this content.
    The dropdown is in cell D32 ... Can anybody let me know why the above doesnt work and what I need to change MsgBox from to open a document path?

    Thanks,
    Chris

  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
    44,552

    Re: VBA Code based on Drop down selection

    It's fussy and, in this case, case sensitive:

    Please Login or Register  to view this content.

    Regards, TMS
    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
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: VBA Code based on Drop down selection

    Hi -

    The only reason I think why it is not working is maybe you're in design mode.

    event

  4. #4
    Registered User
    Join Date
    07-28-2015
    Location
    London, England
    MS-Off Ver
    2011 For Mac
    Posts
    6

    Re: VBA Code based on Drop down selection

    Quote Originally Posted by event21 View Post
    Hi -

    The only reason I think why it is not working is maybe you're in design mode.

    event
    Should this just automatically run when the dropbox in D32 is changed to YES? Or do I need to add the code to a macro? The code is currently just in the VB project .... Which I thought would work as it is on a change event?

  5. #5
    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,552

    Re: VBA Code based on Drop down selection

    @event21: No, it's because, in this case, "YES" <> "yes", or "Yes". Converting the cell value to upper case before making the comparison resolves this issue.

  6. #6
    Registered User
    Join Date
    07-28-2015
    Location
    London, England
    MS-Off Ver
    2011 For Mac
    Posts
    6

    Re: VBA Code based on Drop down selection

    Quote Originally Posted by TMS View Post
    It's fussy and, in this case, case sensitive:

    Please Login or Register  to view this content.

    Regards, TMS
    Thanks TMS - Still doesn't appear to work though .... unless I am doing something wrong. The worksheet is saved as macro-enabled workbook, that code is in the VB project so when cell D32 is changed to YES, that message box should appear? That's correct isnt it?

  7. #7
    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,552

    Re: VBA Code based on Drop down selection

    An event handler needs to be in the Sheet Class Module, not a standard/normal module. Right click on the sheet tab and select View Code. Paste the code there if it is not already there.

  8. #8
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: VBA Code based on Drop down selection

    Hi Chris...

    Try this:

    Please Login or Register  to view this content.
    !If all your troubles are solved, then so is the thread. Show this by marking it so using thread tools at the top of the page.
    If I helped do this, then please show your appreciation by awarding rep points.
    <------ Button for that is over there

  9. #9
    Registered User
    Join Date
    07-28-2015
    Location
    London, England
    MS-Off Ver
    2011 For Mac
    Posts
    6

    Re: VBA Code based on Drop down selection

    Quote Originally Posted by TMS View Post
    An event handler needs to be in the Sheet Class Module, not a standard/normal module. Right click on the sheet tab and select View Code. Paste the code there if it is not already there.
    I knew it would be something simple! Thanks TMS.

    The Message box is now appearing as expected. As for the second part of my query, can this MsgBox be replaced with a location for a source file that will open when YES is selected?

  10. #10
    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,552

    Re: VBA Code based on Drop down selection

    Yes. Record the actions you take when you open the file. Then copy and paste the code (not including the Sub, End Sub lines) where you have the MsgBox.


    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.

+ 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. [SOLVED] using SUMIFS and adding values based on multiple criteria based on selection from the drop
    By muheebrahman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2015, 12:55 AM
  2. Replies: 1
    Last Post: 06-03-2013, 06:30 AM
  3. Replies: 3
    Last Post: 01-31-2013, 06:22 PM
  4. VBA Code to run on selection of drop down menu
    By lealea1982 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2012, 06:51 AM
  5. Auto-update initial drop-down selection based on previous drop-downs
    By thornomad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2010, 09:55 AM
  6. controlling a form drop down based on selection of another drop down
    By flurry in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2006, 11:31 AM
  7. Running code on a drop down selection change
    By Steve Haack in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-26-2005, 12:06 AM

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