+ Reply to Thread
Results 1 to 9 of 9

call a sub when data validation list changes

  1. #1
    Registered User
    Join Date
    07-28-2007
    Posts
    35

    call a sub when data validation list changes

    I have a data validation list in a worksheet that changes the source for a pie chart.
    I have a sub that updates the numbers the source uses.
    I'm trying to get the sub to run when the data list changes (user chooses different drop down value)
    Any suggestions?

    This is the sub
    Please Login or Register  to view this content.
    Mark

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    have you got a ListBox/

    It would be easier to use a ComboBox than Data Validation.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    07-28-2007
    Posts
    35

    data validation list changed to combo box, next?

    Added in a combo box,
    first time using one.
    My code was checking the change event on the cell the data validation was in.
    How do I check the combo box?

    Here is the code so far:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your first code was on a Listbox_Change event, which is why I asked if you were using a ListBox.

    Now you are using a Worksheet_Change Event. can you explain exactly what you are doing?

  5. #5
    Registered User
    Join Date
    07-28-2007
    Posts
    35

    recap

    posted on vbaexpress
    http://www.vbaexpress.com/forum/showthread.php?t=14013
    I have a cell that shows data based on a start and stop date
    using sumproduct.
    I also pull pass or fail info from named range based also on the week range
    I was using a vlookup on the worksheet but the users tend delete cells and I am forced to troubleshoot.
    I can lock sheets, but some macros add and copy and paste, locking won't allow that.
    So, I was working on the idea of having any cell based formula to run in vba and avoid the need to use cells to store a formula or the variables...

    The socond reason for vba over cell based is to make the form work at different office with different data, having dynamic code can scan for used cells and update automaticaly.
    I haven't used combo or list boxes and am still new to data validation list.
    The data list was working but trying to use vba for the vlookup posed a challenge. I got the combobox to trigger the sub, but not sure how to make the combobox list in the sheet (not in a user-form), and how to update the combobox list if the cell data changes (source)
    here is the function I have so far..
    I call the function from a sheet change event.
    Please Login or Register  to view this content.
    Last edited by mperrah; 07-30-2007 at 03:01 PM.

  6. #6
    Registered User
    Join Date
    08-08-2007
    Posts
    9
    I'm not sure if you have solved this, but here's my 2 cents.
    I had the same problem with being abe to detect the change event of a specific data validation list. Turns out that it's nearly just as easy to catch as a ListBox or Combo event.

    Just name the data validation cell and check its address against the Target.Address in the Worksheet_Change event.

    Please Login or Register  to view this content.
    Hope this helps you or anyone else.

  7. #7
    Registered User
    Join Date
    07-28-2007
    Posts
    35

    not solved yet

    I like the idea. I can capture the event, but not sure how to turn a vlookup into a vba code
    =VLOOKUP(AD35,AJ7:AL67, 3)
    this vlookup scans the data validation list in AD35,
    the vlookup checks a pasted link to another page with the tech numbers.
    The 3rd column has the match, then the chart updates.
    I just need the code off the sheet to avoid deletion and have it dynamic if the source changes size,
    or gets out of numerical order (my code fails if the techs aren't sorted)

    this is how I started with your code...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-08-2007
    Posts
    9
    Not really sure how to implement the vlookup in VBA other than to hard code the process through iteration and offsets. I use this quite often. I'm sure there is a simpler or more elegant way to do it, but it works for me.

    i.e.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-28-2007
    Posts
    35

    Thumbs up Thank You!

    That was the trick,
    I altered a little to match my names and sources and all is well in vba
    Thank you so much.
    Here is what I'm using to simulate a vlookup using vba
    Please Login or Register  to view this content.
    Mark

+ 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