+ Reply to Thread
Results 1 to 17 of 17

Contour Graphs

  1. #1
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    Contour Graphs

    Hello,

    I have 4 contour graphs (see tab labeled 'Charts') that are updating based on the data from 4 dynamic data tables (see cells AE21:AJ51 on 'Mov_Avg_Chart' tab). The values in the dynamic data tables change based on the inputs in the optimisation table (see cells B22:B27 in 'Mov_Avg_Chart' tab). The automatic generation of the data tables and the 4 contour graphs has been implemented through a macro (named 'X'). Once you hit the update button next to the optimisation table, the data tables update, as do the 4 contour graphs. The graphs end up being loaded on top of each other, but if you move each one out of the way, you can see them. I am having 3 issues which I cannot seem to figure out:

    1) The axes on the contour graphs are switched. That is, the values on the x-axis should be on the y-axis and vice versa. I am not sure how to switch these.

    2) I would like each contour graph to have a title, based on the statistic that is being optimised in the top left cell in each data table. For example, chart 1 is an optimisation of the Annualized Return (see cell AE21, which is referencing cell AF7, which is the annualized return).

    3) My calculation method is currently set to 'automatic except data tables.' However, whenever I hit the 'update' button next to the optimisation table, the calculation method switches to automatic. I'm guessing this may be due to the way the macro was written. Would someone be able to look at the macro and see if it is written in the way it should be?

    I have been trying to go through these 3 issues all weekend, and would appreciate any assistance. I have attached a condensed version of my file.

    Kind Regards,

    Maani
    Attached Files Attached Files
    Last edited by maani; 09-01-2009 at 09:44 AM.

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

    re: Contour Graphs

    1. If you change the layout of your data slightly, so the top left corner of the data matrix is empty you can use the Switch Row/Column button on the Design tab to switch Axis.
    Note this will affect your update macro.

    2. You can link the chart title to a cell.
    http://www.andypope.info/tips/tip001.htm

    3. Your code is setting calculation back to automatic at the end of the update routine.
    Please Login or Register  to view this content.
    Last edited by Andy Pope; 08-24-2009 at 11:30 AM.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Hi Andy,

    Thanks for your response and help.

    1) If I change the layout as you suggested to leave the top left cell empty, where would I put the statistic that I seek to optimise (the cell that is currently highlighted). Also, how would the code need to be changed? I have tried to play around with this by switching the xlRows and xlColumns in the code but this doesn't work.

    2) Thanks for the link on this. Is there a way to automate it? The ranges of the charts and values are always changing and thus I wanted something to be able to automate this by putting it into the macro. Is this possible?

    3) When I changed the code to
    Please Login or Register  to view this content.
    the data table doesn't update. That is why it was set to xlCalculationAutomatic. is there a way to have it so that the calculation method remains what it is. That is, if it is set at 'automatic except for data tables' unless i hit the update button and after I hit update it goes back to 'automatic except for data tables'?

    Thanks again,

    Maani
    Last edited by maani; 08-24-2009 at 11:44 AM.

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

    re: Contour Graphs

    Just move the topleft cell of the tables over 1 column or up 1.
    Anything to help excel use the top row/column as axis labels.

    I will try and look at your code tomorrow.

    Using the macro recorder setting Calculation except for tables generates this code.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Thanks for your response, Andy.

    1) I kept the top-left cell of each data table empty, but the optimised statistic appears in the cell nonetheless once I hit update. Also, by moving the top-left value to a column up or across, it will affect the macro because it's been set to be a dynamic data table, so it will take values above and to the right of the data table. The reason I did this was so that the data table could adjust to an increase and decrease in values from the optimisation table (cells B22:B27).

    3) I also tried to change the code to the one you mentioned below, but the data table didn't update when using this.

    Thanks for taking the time to look at the code tomorrow. This has been something of a work in progress for quite awhile now, and as Stephen points out, there has been another thread on this same topic. Thanks to Stephen's help with the code, I have gotten to this point.

    Thanks for your time,

    Maani
    Last edited by maani; 08-24-2009 at 02:48 PM.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    re: Contour Graphs

    In case it's of use, here is the original thread:
    http://www.excelforum.com/excel-prog...a-table-4.html

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

    re: Contour Graphs

    Revised code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Hi Andy,

    Thank you so much for taking the time out to look through the code. This revised code has done exactly what I had wanted by switching the axes and also by setting the calculation method to remain as 'automatic except data tables.' What was the line of code that enables you to switch the axes? Also, the code you used below
    Please Login or Register  to view this content.
    for setting the calculation method to remain as what it was, could you explain the line of code and how it works? I had not come across it before.

    With regard to chart titles, when I followed the directions on your link about setting a dynamic title in a chart, I could not seem to do this as every time I clicked the charts title (Chart 1 for example) and then put in the cell reference in the formula bar, the title does not come up. I also tried to manually add the chart title from the layout tab but that would not take a cell reference either. Would you know how to do this? Also, I would like to do this for the axis titles.

    Thanks again,

    Maani

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

    re: Contour Graphs

    For chart titles add these lines to the routine

    Please Login or Register  to view this content.
    At the start of the routine I store the current calculation setting in a variable, lngCalcMode, just before setting calculation to Manual.

    Then at the end I restore calculation mode to the setting.

    I did not have to switch the axes as that is the default for that matrix of data. If the matrix dimensions change then you may need to force a plot by rows

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Hi Andy,

    Thanks for the chart title code. I have put in the updated code and a title comes up, but it seems to be the value in the top-left cell that is the title. For example, in chart 1 the title is -10.44 (it is taking the value in cell AE21) instead of the desired AE7. Chart 2 is supposed to be the value in AE9; Chart 3 the value in AE10 and Chart 4 the value in AE10.

    Thanks for the explanation on calculation settings.

    With regard to the code you provided to force a plot by rows, where would I put that if I needed it? Also, you said that I may need that if the matrix dimensions change. The dimensions are changing everytime I change the values in the optimisation table. I have tried changing the values in the optimisation table and hitting update which would give me different dimensions in the data tables (number of rows to columns), and the x and y axis values both plot correctly.

    I have attached the worksheet for your convenience.

    Thanks,

    Maani
    Attached Files Attached Files

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

    re: Contour Graphs

    Make the change after the chart has data in it.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Many thanks, Andy. That worked perfectly.

    Regards,

    Maani

  13. #13
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Hi Andy,

    I just noticed that another macro I have in my workbook looks like it has been affected by the existance of the data table and the contour graphs. That is, when I hit the 'update' button on the 'BBG Raw Data' tab, calculation mode switches from 'automatic except data tables' to 'automatic.' This particular macro is not supposed to update data tables, but for some reason it is; it is simply trying to update data from one sheet to another. I tried to store the current calculation setting in a variable, lngCalcMode, as you had done prior to setting the calculation mode to Manual, but it still is updating the data tables when I hit update. The code is as follows:

    Please Login or Register  to view this content.
    How would this particular macro need to change in order to run so that when I hit 'update', it doesn't update the data tables?

    Thanks,

    Maani

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

    re: Contour Graphs

    That code sets calculation back to automatic.

    Use the same approach as before. Store the value before setting to manual.
    Restore to content of variable rather than explicitly back to automatic.

  15. #15
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    Would this be correct?

    Please Login or Register  to view this content.

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

    re: Contour Graphs

    Correct in the sense of the code yes.

    What state is calculation in when the routine has finished?
    Perhaps the X_Axis_Scale routine is changing things as well.

  17. #17
    Registered User
    Join Date
    05-26-2009
    Location
    new york
    MS-Off Ver
    Excel 2007
    Posts
    76

    re: Contour Graphs

    It's in automatic except data tables. It seems to be working. The only issue is that my original worksheet (this is a condensed version) is very large and thus it takes quite a bit of time everytime the data tables recalculate. is there a way to make the recalculation of the data tables go faster? Or to have the data tables not recalculate upon saving the worksheet?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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