+ Reply to Thread
Results 1 to 27 of 27

Pull data based on a drop down selection

  1. #1
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Pull data based on a drop down selection

    Hoping someone can help, i'm a bit inexperienced with macros.

    Basically what i want to do is have a user select an option via a drop down list. I need a macros that will read the selected option then pull data from a corresponding worksheet. The selected option will be in column A and wherever it appears the macros would automatically pull that whole row i.e. the the corresponding values in column b, c, d, etc. Is this straight forward?

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi jtd84
    Is this straight forward?
    It's probably me, but no.
    1. What's in the Drop Down List?
    2. How does the Drop Down List get populated?
    3. Will the selected Option appear more than once in Column A of the corresponding worksheet?
    4. Pull the whole row to where?
    A sample of what you have and what you'd like it to be could possibly clear up my questions.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Hey mate,

    1. It's a list of sales managers.
    2. I've just entered the names into a list and built the drop down from that list via data validation.
    3. Yes it will appear more than once. Column A will list the managers out while column B will have customers and then the following columns will have sales figures by date.
    4. I want to pull it into the next tab so that it lists out the chosen sales manager and their customers with corresponding sales. Would like it in a crosstab format with dates along the top.

    Probably a silly question but how do i attach items?

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi jtd84

    There are no "silly" questions but I must admit, I don't understand your question
    Please Login or Register  to view this content.
    What's an item? What do you mean by "attach"?

    Please post a sample of your file with what you have and what you'd like it to be.

    John

  5. #5
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Sorry, I meant attach files so you could see what I meant. I think i've managed to attach it. Basically i want to choose a person's name via the drop down and then have that persons customer plus their sales by day populate in the next sheet exactly as it appears in the first sheet. Hope that makes sense.

    Thanks
    Attached Files Attached Files

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi jtd84

    Your file helps but it's 11:00 PM here. I'll look at this in the morning and get back to you.

    John

  7. #7
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    No problem, thanks for your help mate.

    John

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi jtd84

    I don't know where you're going with this. The attached will display data by the persons name. If this is not sufficient, I need your next requirement.

    Let me know where you want to go.

    John
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Hi John,

    Sorry i probably haven't explained this too well. This is just an example of what I have, there are a lot more managers/customers than this. I've added a bit more data and alterd the spreadsheet a bit to maybe explain it better. Sheet1 will have the data dump (which will be a lot larger than what's there). Ideally when a manager goes to use it, they'll choose their name from the drop down in Sheet2 and basically what i need to do is figure out a macros that will read cell D1 in sheet2, search column D in sheet1 and return that row (i.e. the customer and figures in that row). From this i can set up graphs that will populate with the data for the selected manager only. I've pasted the relevant data into sheet2 and added a quick graph to show what it would look like ideally. Appreciate your help.

    John
    Attached Files Attached Files

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi John

    Try the attached. Let me know of issues.

    John
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Hi John,

    thanks for that. I've just copied it into my spreadsheet and when i've run i've received a run time error '9'. it says subscript out of range. It refers to the line below.

    Sheets("Sheet3").UsedRange.Offset(2, 0).ClearContents

    Could you explain what this means please? I changed it to "Sheet3" as this is where the orginal data dump is located.

    Thanks,
    John

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi John

    Please ALWAYS wrap your code in code tags, even if it's only one line. The Administrators are VERY particular about that.

    First question I should ask is did the sample file work for you?

    This line of code
    Please Login or Register  to view this content.
    is clearing the contents of the last filtered data that was extracted from your Data dump.

    It's a little confusing because in your sample file, Sheet1 (code name) is actually Sheet2 tab and Sheet2 (code name) is actually Sheet1 tab.

    Long story short, on what TAB name is your drop down list? That's the sheet that should be getting cleared by the code.

    If it gives you problems, let me know.

    John

  13. #13
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Sorry about that, still new to this. I've managed to get it working now, it was to do with the tab names. I'll let you know if i get stuck again.

    cheers,
    John

  14. #14
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Need a macros that will pull data based on a drop down selection

    Hi John,

    Thanks for your help on this one, the code you gave me earlier worked perfectly. Hoping you can help me out with something else i've got that follows on from the earlier piece.

    On a new tab (Workings), i've set up some formulas that pull from the data in sheet2. Obviously these workings will change depending on the sales manager selected which will in turn change the Workings tab. I have some graphs set up on the last tab that feed off the Workings tab. What i want to be able to do is set up a macros that will automatically pull the data from the workings tab and plot it in seperate graphs.The data dump that feeds the whole file will always have a different time period so if i just add graphs like i have now, i'll always have to go in and adjust the range for each graph. Ideally i could have a macros that plots the graphs and automatically works out the range. Is this possible? I've attached the original file with new tabs to give you an idea of the desired outcome.

    Thanks,
    John
    Attached Files Attached Files

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need a macros that will pull data based on a drop down selection

    Hi John

    Gotta be honest with you. I know squat about charts and graphs. If you wish truly qualified help on this, I'd recommend starting a new thread.

    Sorry but I don't have the experience to help with this.

    John

  16. #16
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Pull data based on a drop down selection

    Hi John,

    No worries mate, you've been a massive help already. Appreciate it.

    John

  17. #17
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Pull data based on a drop down selection

    Hi John,

    In the last file you attached, what alteration would i make to the code if i wanted to have the dropdown in another tab? i.e. have the sales manager drop down on sheet 3 instead.

    Thanks,
    John

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull data based on a drop down selection

    Hi John

    I'm about ready to go to bed tonight. It's going on midnight here and I have Grandson duty in the AM. I'll look at this for you tomorrow.

    John

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull data based on a drop down selection

    Hi John



    You'll need to do several things:

    1. Sheet3 (in the workbook I posted) contains a Named Range "Managers; you'll need to copy the contents of Sheet3 to another blank worksheet, say Sheet4

    2. Then change the reference in the Named Range Manager to the new Sheet name.

    3. Move the code from behind Tab Sheet2 to behind Tab Sheet3
      Right Click on Tab Sheet2 and select View Code. That'll take you to the VBA screen. Click on Edit->Select All->Cut
      Right Click on Tab Sheet3 and select View Code; paste the clipboard in the box on the right.

    4. In Module1, change all references from Sheet2 to Sheet3 (I believe there are 3)

    5. Copy Tab Sheet2 Cells C1:D1 to Tab Sheet3 Cells C1
    Alternately, see attached.

    John
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Pull data based on a drop down selection

    Hi John,

    Sorry, I don't think i explained it properly. What i was after was to have the data remaining on sheet2, with the dropdown on sheet3. At the moment, i think you have the dropdown on sheet3 and it's changing the data on sheet3. The reason i'm trying to do it this way is because i want to hide sheet2 (with the data) and have a page with graphs (sheet3). Ideally when a user opens the file, all they'll see is a page of graphs with a dropdown at the top of the page. When they change the dropdown, the data will update in the background and feed the graphs. Is this possible by just tweaking the code?

    Thanks,
    John

  21. #21
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull data based on a drop down selection

    Hi John

    Ah, I see. I'd think this is possible. Let me look at it. Have Grandpa duty again tonight but may have something for you later this evening.

    John

  22. #22
    Registered User
    Join Date
    03-14-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Pull data based on a drop down selection

    thanks so much, really appreciate it

  23. #23
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull data based on a drop down selection

    Hi John

    See if this attachment does as you described.

    John
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    10-13-2010
    Location
    Malvern, AR
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Pull data based on a drop down selection

    I know that this post is kind of old, but I think this answers part of my question I had today. Here is my situation:

    I have a list of 250 agents. Next to each agents name is the name of there manager. There are about 13 managers. Column A has the agents, Column B has the TM. Basically, using data validation I want the following: When I choose a TM from the drop down box, I want the agents assigned to them to populate in another drop down box. I think this will do it it somewhat, I just want to be able to understand how this works so I can use it for my function.

  25. #25
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Pull data based on a drop down selection

    Hi Chris

    You'll need to post your own thread.

    Rule 2 Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread

    Please post your own thread. Any of us will be happy to help you.

    John

  26. #26
    Registered User
    Join Date
    02-29-2012
    Location
    Connecticut
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Pull data based on a drop down selection

    This file was helpful in a project I was working on, but I am wondering if there is a way 4 criterias can be used? Any filter on these criteri would bring back data corresponding with the filtered criteria. If so how can I modify the code in the attached file to address this.

  27. #27
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Pull data based on a drop down selection

    Hello remysteve262, and welcome to the forum.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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