+ Reply to Thread
Results 1 to 24 of 24

Macro to select data via input box's

  1. #1
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Macro to select data via input box's

    Hello,

    I'm attempting to write my first macro from scratch and have not been able to figure out if I'm even in the ballpark on the structure and direction of my code. What I'm trying to accomplish is for a user to be able to select a range of data (weekending dates) that will populate an existing graph(example attached). The graph is updated weekly and if all the user has to do is enter two dates and the macro will use those dates to find the range of data to populate the graph. Anyways, here is my poor attempt:

    Please Login or Register  to view this content.
    I'm sure there is a mush better approach at this but I'm not sure how to do it. If anyone has the time to either help with my existing code or show me a better approach, I would appreciate it a lot.

    Thank you,

    -Justair07
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Probably something along the lines of:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    yudlugar,

    That worked great, thank you very much! I'm glad to know I was off to the right start but I never would of figured out the rest. One thing I did notice though is that the chart does not show data more than five dates or less than five. Is this something you can help me figure out?

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    I'd guess the way to do it would be to delete the existing seriescollection and then add a new one with the data range you want but I'm not sure. Afraid I don't have the time to take a look now but I'll get onto later if I can.

  5. #5
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Quote Originally Posted by Justair07 View Post
    yudlugar,

    That worked great, thank you very much! I'm glad to know I was off to the right start but I never would of figured out the rest. One thing I did notice though is that the chart does not show data more than five dates or less than five. Is this something you can help me figure out?
    I also just relized that the data never changes, only the dates. Any ideas?

  6. #6
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Quote Originally Posted by yudlugar View Post
    I'd guess the way to do it would be to delete the existing seriescollection and then add a new one with the data range you want but I'm not sure. Afraid I don't have the time to take a look now but I'll get onto later if I can.
    Ok thanks again

  7. #7
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    So I was looking at better ways to select the data and I believe this is what I need to build off of appose to what I was using before.

    Please Login or Register  to view this content.
    This will select the range for the dates and the Actual Rejection %, I'm just not sure how to use this with GetRange?

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Probably easiest to use it with two variables for start and end row and build the string to assign to the source data from there:

    Please Login or Register  to view this content.
    Last edited by ragulduy; 09-18-2013 at 04:18 AM.

  9. #9
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Hi yudlugar,

    I'm getting "invalid qualifier" error for Address:

    Please Login or Register  to view this content.
    Any ideas?

    Thanks again

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Sorry, get rid of the address bit:
    Range("A" & Searchrow).row

  11. #11
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    yudlugar,

    Works perfect! thanks so much for the help!

  12. #12
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    So I tried to add the code to a command button but for some reason it won't work, I keep getting a Method 'Range' of object'_Worksheet failed run-time error on the very last line of code.

    Any ideas why?

  13. #13
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Change the last line to:
    msgbox("Sheet1!$A$1,Sheet1!$D$1:$E$1,Sheet1!$A$" & GetRangestart & ":$A$" & GetRangeend & ",Sheet1!$D$" & GetRangestart & ":$E$" & GetRangeend & "")

    What do you get in the messagebox and does it look like a reasonable range reference?

  14. #14
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    It won't run, I'm getting a 'type mismatch' for msgbox

  15. #15
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Just looked and I think it's got "") on the end when it shoudl be ")", that might be the problem.

  16. #16
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Here is what i put

    ActiveChart.SetSourceData Source:=MsgBox("Sheet2!$A$1,Sheet2!$D$1:$E$1,Sheet2!$A$" & GetRangestart & ":$A$" & GetRangeend & ",Sheet2!$D$" & GetRangestart & ":$E$" & GetRangeend & ")"

    but i'm getting a compile error

  17. #17
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Here is what I tried as well but got a compile error:

    ActiveChart.SetSourceData Source:=Range("Sheet2!$A$1,Sheet2!$D$1:$E$1,Sheet2!$A$" & GetRangestart & ":$A$" & GetRangeend & ",Sheet2!$D$" & GetRangestart & ":$E$" & GetRangeend & ")"

  18. #18
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Sorry, I meant replace the whole line with msgbox(...), delete the "activechart.setsourcedata source:=" part, what you end up with in the messagebox is what you will be setting your range to, it should probably be:
    MsgBox("Sheet2!$A$1,Sheet2!$D$1:$E$1,Sheet2!$A$" & GetRangestart & ":$A$" & GetRangeend & ",Sheet2!$D$" & GetRangestart & ":$E$" & GetRangeend)

    I think.

  19. #19
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Here is my msgbox reply

    123.jpg

    Fyi, I did modify the code to work with a chart that is on a different worksheet but it works fine as long as I don't use a command button.

  20. #20
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Still no luck, I tried to reuse the msgbox as the new range but it didnt work

  21. #21
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Can't see any obvious problems, could you upload your workbook with the macro in that isn't working?

  22. #22
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Here you go...

    Thanks again,
    Attached Files Attached Files

  23. #23
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to select data via input box's

    Sorry, haven't got a clue why that isn't working ....

  24. #24
    Forum Contributor
    Join Date
    01-08-2013
    Location
    Jacksonville, Fl
    MS-Off Ver
    Excel 2016
    Posts
    355

    Re: Macro to select data via input box's

    Oh well, no big deal. I can just use a form button. Thanks for all the help!

+ 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] input date column A, increment B, select blank cell in D and input time. in a macro
    By jeffstu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2012, 11:19 AM
  2. select from a data range depending on a certain cell input.
    By Andism in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-11-2012, 11:38 AM
  3. Select a set of data that matchs a range then input said data into a new column SOS
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2012, 07:46 PM
  4. Select Data Based on User Input
    By scurveydog in forum Excel General
    Replies: 2
    Last Post: 10-03-2010, 12:31 PM
  5. Select next column after data input into InputBox
    By Icanthearkinda in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-19-2009, 03:50 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