+ Reply to Thread
Results 1 to 14 of 14

Change data source of a sheet by a dropdown (data validation)

  1. #1
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Question Change data source of a sheet by a dropdown (data validation)

    Hello,

    I have a workbook containing sheets A, B, C, ... as well as an evaluation sheet.
    A, B, C are congruently set-up.

    On the evaluation sheet, I'd like to have a data validation drop down fulfilling two requirements:

    1. Contains "A", "B", "C", ... (and more, if sheets are added) as content to choose
    2. If e.g. "B", is chosen, all formulas of the evaluation sheet shall adapt accordingly: =SUM(B!B3:B7) (choosing "A" leads to "=SUM(A!B3:B7)"

    As the INDIRECT functions decrease the speed of the file, a VBA solution is preferred.

    Can anybody help me?

    Thank you very much for every hint

    Florian

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    See next code and file attached
    Please Login or Register  to view this content.
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Wow!
    Great!

    How to modify the code if only formulas in the range A50:ZZ200 shall be dependent on the dropdown?

    Possible?

    Thank you so much

    Regards

    Florian

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    See new code
    Notice where the range address is recoded
    Please Login or Register  to view this content.
    for the next adjstment ...!

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Dear PCI,

    thanks a lot for the updated script.

    I am currently working with the script you posted on 12-25-2017, 11:06 PM

    I just noted the following:

    - the formulas do change as long as I choose A or B as data source, but not the one in C10
    - as soon as I choose C as data source, the formula change correctly, but afterwards, when I choose A or B again, the formulas are not updated

    What might be wrong here?

    And an additional question for interest (as I have very less VBA knowledge): what is the line "Set WSDic = CreateObject("Scripting.Dictionary")" for and where can this object be found?

    Thank you so much in advance for your help and clarification

    Regards

    Florian

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    Not sure to get it right:
    "not the one in C10" but C10 is not the working range: "A50:ZZ200"
    Can you make test with the file attached and comment.
    Concerning CreateObject("Scripting.Dictionary")
    It is in fact a collection used to make the list of the sheets and permit to reuse this list easely: an Arraylist could be used
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Dear PCI,

    thanks again for your reply.
    I adapted the working range from A6 to ZZ200 and tried it again.
    It still only works limited as described in the thread before:
    1) choosing "A" and click update: values in C6/C7/C8/C9 do change, value in C10 does not change
    2) then choosing "B" and click update: values in C6/C7/C8/C9 do change, value in C10 does not change
    3) then choosing "C" and click update: values in C6/C7/C8/C9 do change, value in C10 remains 1500 (which is correct)
    4) then choosing "A" and click update: no change of any value

    Looking to the formula in C6 after step 1: =SUM(A!B3:B7)
    Looking to the formula in C6 after step 2: =SUM(B!B3:B7)
    Looking to the formula in C6 after step 3: =SUM('C'!B3:B7)
    Looking to the formula in C6 after step 4: =SUM('C'!B3:B7)

    =>Are the "superscripted commas" in 'C' the problem?

    Florian

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    "Are the "superscripted commas" in 'C' the problem?" YES certainly
    Can you send a sample of your file ??

  9. #9
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Dear PCI,

    please find attached my file

    Regards

    Florian
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    OK clear, I forgot how Excel could work with sheet's name in formula
    Try next code
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Dear PCI,

    thank you so much for the code modification.

    It seems to work now.

    May I ask you two additional things:

    - how to handle sheet names other than A, B, or C, which might be more than one word (e.g. "San Marino")?
    - how to handle a non-continuous range (e.g. A6:G200 and K6:ZZ200 instead of A6:ZZ200)?

    Heavily more work for you?

    Regards

    Florian

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Change data source of a sheet by a dropdown (data validation)

    See here update
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-25-2017
    Location
    Switzerland
    MS-Off Ver
    2016
    Posts
    25

    Re: Change data source of a sheet by a dropdown (data validation)

    Dear PSI,

    just woke up and immediately checked my mailbox and your updated listing:

    IT WORKS PERFECTLY!

    THANK YOU VERY MUCH!

    Regards

    Florian

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,763

    Re: Change data source of a sheet by a dropdown (data validation)

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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] Data validation lists change source designation when list data is updated.
    By frenurks in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-28-2015, 06:52 AM
  2. Replies: 1
    Last Post: 07-28-2014, 06:09 PM
  3. Match data on source and destination sheet and change value
    By Cammandk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-25-2014, 03:18 PM
  4. [SOLVED] Using a dropdown menu to change data on a master sheet
    By elmerg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2013, 05:24 AM
  5. change data validation cell when source changes
    By ninny76 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2013, 03:21 AM
  6. data validation-Can the source of the validation criteria be dfrom a different sheet?
    By yael pinkert in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-07-2009, 04:28 AM
  7. combo box from data validation with source list in separate sheet
    By Jay Trull in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-06-2006, 10:10 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