+ Reply to Thread
Results 1 to 18 of 18

Creating chart, conditional on cell clicked

  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Creating chart, conditional on cell clicked

    Ok fellas, this is a very complicated one, so I'm searching for a VBA champion.
    I need to make this graph using. All the data to be used is in the sheet 'DataforGrid' under the 2nd Table. Ineed the graph to look like 'Chart B' which I have pasted from another source under the coloured Heatmap. The way it should work is that there will be 2 scroll bars to select 2 dates. Then based on those 2 dates - two lines are graphed one for each date. you can ignore the bar charts on 'chart B'....the 2 lines will have 8 data points (as there are 8 Terms for each product on the heatmap grid, and 8 products for each Term)
    So what data will these 2 lines cover?

    Look at the heatmap - you see Product and Term. Outside the coloured boxes you can see the categories of product and term. Row 4 has product, and Column B has Term.
    What I want to do is be able to click on say cell B7 (which is 1m), when I do this i want to graph the values of (1m in 1y, 1m in 2y, 1m in 5y, 1m in 7y and so on till 1m in 30y)----lets call it horizontal charting. That is 8 values/points on the line, im not charting these entire series but rather, just for the 2 dates that were selected in the scroll bar...this is to show the difference between the values of the term/product on those dates.
    now the same thing needs to be done vertically so if i select a Product 30y....it will chart --1m in 30y, 3m in 30y, 6m in 30y all teh way to 10y in 30, thats 8 points.
    So in total there are 16 different cells that I should be able to click, 8 product, 8 term.


    If we are charting a 'Term' then x-axis will have the 8 products and the chart label will be the 'Term' category-eg. 5Y, Y axis will have the values on that day(ignore the 2nd y-axis on Chart B which has some weird figures


    (****In sheet ' DataforGrid' you will see categories like 3m in 7y, etc the first item is always term, the 2nd is product
    so remember its 'Term in Product')

    I hope I wasnt confusing, if so let me know and I will try to explain better

    any help would be much appreciated, I understand this can be quite difficult so my expectations are not that high

    thanks for reading, and good luck (i need more than just luck here)
    Attached Files Attached Files
    Last edited by Pasha81; 06-13-2009 at 06:38 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Creating chart, conditional on cell clicked

    You do not need VBA to do this.

    You can use Data validation for the selection of Dates, Term/Product, specific term/product.

    Then with the 4 pieces of information you can use formula to locate the required chart labels and data values.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi there,

    Well, you were right - it was a bit complicated - not too difficult to program, but not all that easy to understand!

    Please take a look at the attached and let me know if I've understood your requirements correctly. The only thing the user has to do is to enter the required dates and then select the required values of Term and Product from the dropdown lists. The graphs will update automatically.

    I'd be glad to have your feedback on this one, even if it's only to let me know that I've completely misunderstood what you had in mind!

    Regards,

    Greg M
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    sorry, i know its not easy to understand as i've got 'Years/ time' on both axes...but you guys got it right.
    Excellent work, both of you Greg and Andy! Looks like you guys put some time in for this, definitely does the job and looks organised.
    But do you know by any chance if the dates could be selected with a scrollbar, just that I was asked to do it with scrollbars for ease of use.

    thanks a lot guys...both versions work

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    I originally thought about using dropdown lists for the dates, and doing this will avoid the possibility of entering a date for which no data are available. However, the possible disadvantage is that users may have to scroll down through several hundred dates on the list, and this might prove to be more trouble than it's worth.

    It's not a problem to make the dates available from a dropdown list, but are you sure that's the best approach?

    Incidentally, if you're interested, I produced a slightly modified version of the workbook which would allow you to change the layout of your main data worksheet, i.e. to have more/fewer columns before the date column, and more/fewer rows before the title column.

    Please let me know if you want me to implement the date dropdown list or anything else.

    Regards,

    Greg M

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Creating chart, conditional on cell clicked

    You can use a scrollbar. If you use a scrollbar from the forms toolbar you can link it's value to a cell. This value would then be used as the row index for the available dates.

    The only problem is the Maximum value of the scroll bar can not linked to a cell or formula. So if the number of dates increases you will need to increase the maximum value of your scroll bar.
    You can set the maximum very high and then use formula to cap the maximum value used for the INDEX formula to be that of the maximum date values.

  7. #7
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    thanks guys, i'll just try plugging in a scrollbar, i've tried before and failed i'll give it another shot

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    Take a look at the attached workbook and see if the scrollbar does what you want.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    Sorry - try this version instead! It will cope with up to 1000 dates.

    Please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    thanks Greg, the scroll bar does work like i wanted, now I'll try plugging it into my sheet, hopefully i can make it work there like you did, i'm surprised there was no vba required at all for the whole charting process

  11. #11
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    Thanks for your feedback - I'm glad I was able to help.

    Ok on not needing VBA for the chart updating. I usually find that it's easier to "point" a chart at a specific range and to manipulate the contents of that range, than to try to manipulate the chart itself. As a consequence, the amount of VBA required is often very little, and relates just to updating one or two cells whose values are then used to populate the data range .

    Regards,

    Greg M

  12. #12
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    I'll mark this solved now, sorry about the delay was travelling last few days.
    You guys did a fantastic job hee, thanks....though I just cant get my scrollbar to work, I'm making some very basic mistake I'm sure, but that's ok. If I run in to any problems while making additions to the model I'll let you know

    thanks again

  13. #13
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    Hi Greg,

    here's the scrollbar issue, when I tried to link it to the cell 'ptrScrollOffset1' the scrollbar disappeared...

    Oh and another thing, about labelling the chart -- on the current version for Term 1y, see that on the X-axis we have 1y in 1y, 1y in 2y, 1y in 5y etc... is there a way to make that 1y,2y,5y, and so on till 30y on the X-axis, and at the top of the chart it'll say Term 1y.....

    something like that, would make it look more concise, whats the formula for that, do i type it into Chart Title after selecting chart options?


    thanks again buddy
    Attached Files Attached Files

  14. #14
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    Ok - I think things started to go wrong for you when you decided to use the Activex scrollbar (from the Control Toolbox toolbar) rather than the one you find on the Forms toolbar. Activex controls are more powerful, but also less user-friendly.

    I've adjusted the x-axis titles on the attached version and hope that I've got them the way you wanted.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    thanks Greg..

    i didnt know about the forms scrollbar before, it is way easier for sure, but
    something's wrong I'm getting dates from Jan 2000 to Sep 2002 which is not even in my range so its giving me a blank graph. Am I supposed to hihlight the Dates Range in 'Data' while making thescrollbar?

  16. #16
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    I've included the latest version with only minor modifications which you probably won't even notice.

    Ok, I'll try to talk you through the way Scrollbar_1 (the one in Cell M8 of the "Graphs" worksheet) works.

    The Cell Link property of Scrollbar_1 is the named cell "ptrScrollOffset1" (H47) of the "Graph data" sheet, so the value in this cell will increase/decrease in response to clicking on Scrollbar_1.

    So what happens next? We need to scroll down through the dates in Column B of the "Data" sheet, beginning at "StartCell" (Cell B16), and pick the Nth date cell, where N corresponds to the value stored in Cell H47.

    The named cell "ptrDateStartCell" (D47) on the "Graph Data" sheet contains the address of "StartCell", i.e. '[Heat Map - 6.xls]Data'!$B$16. This address is calculated AUTOMATICALLY from the values stored in the named cells "ptrSourceSheet" (K29), "ptrSourceColumn" (K30) and "ptrSourceRow" (K31) - the workbook name is entered automatically by the Cell("Address", ....) formula in Cell D47.

    The formula in the named cell "ptrScrollDate1" (J47) uses the address of "StartCell" as its reference point and the value of "ptrScrollOffset1" (H47) as its offset to pick a date from the list. This date is simply repeated in Cell C30. If the offset selects a date beyond the end of the list (i.e. beyond Cell B528) , the Cells J47 and C30 will display "End of Range", and the formula in the named cell "ptrNoData1" (E30) will display "No Data Available".

    You shouldn't have to modify or select anything in the workbook in order to use it. The sheets are protected, and the only unlocked cells in the workbook are Cells H47 & H48 on the "Graph Data" sheet, which are accessed by the scrollbar controls. In addition, Cells K29, K30 & K31 on this sheet are unlocked in order to cater for any alterations to the name or layout of the "Data" sheet.

    I hope this explanation helps - please let me know if there's anything else you need.

    Regards,

    Greg M
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    05-13-2009
    Location
    London, England
    MS-Off Ver
    Excel XP
    Posts
    174

    Re: Creating chart, conditional on cell clicked

    I realized my mistake, it was with the defined names, I had messed up with one of them, they all seemed so similar, silly error haha
    thanks a bunch dude, you really put in a lot of time for this
    you should be charging money!

    Must say its a cool learning experience for me too...there's just so much excel can do..

  18. #18
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Creating chart, conditional on cell clicked

    Hi again,

    Many thanks for your feedback. I'm glad to hear that things are working correctly at your end, and pleased that I was able to help.

    You're right - Excel is one incredible application!

    Regards,

    Greg M

+ 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