+ Reply to Thread
Results 1 to 3 of 3

Button Macro to Recreate Graph With New Y-axis Values

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Button Macro to Recreate Graph With New Y-axis Values

    I am trying to create a macro so that when the user clicks a next button the graph is redrawn with the next row of text. X-Values are always H1:KD2, Y-Values are H2:KD2 for the first graph. I would also like to flip the Y-axis values on graph creation so it changes its direction. As they go to the next line it would also be nice if there was a combo box that updated to show the value in column E to the corresponding current row so the user knew which station they were viewing and potentially could jump to stations using the combo box and it would recreate the graph with the corresponding row of data.
    Please _HELP.csv

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Button Macro to Recreate Graph With New Y-axis Values

    I'm not sure what you mean by "Flip the y-Axis values" I'll assume you mean, reverse the direction, so 1, 2, 3 gets plotted as 3, 2, 1. Format axis -> "Values in reverse order" will do that.

    First I added a couple of rows to give you an area to define which data set you want to plot. I set up a data validation of type list with allowable values of 1,2,3,4 in cell B1.

    You don't need VBA to do this. Named ranges will do the trick. I highlighted the range H1:KD1 and named it X_Axis.

    Then I defined a name Y_Axis as =OFFSET(X_Axis,'Please _HELP'!$B$1,1) this gives the same range as X_Axis, but whatever the value in B1 is rows down.

    I assume you want an X-Y plot. So what I did was highlight cells H3:L4 - I could have selected any number of columns, I just wanted to have something to create a chart. With this range, I made the X-Y plot and reversed the Y Axis.

    Then I right clicked on the chart and selected Select Data. There is only one series to select. Select it and click on Edit. For the Series X Values Replace ='Please _HELP.xlsb'!$H$3:$L$3 with ='Please _HELP.xlsb'!X_Axis. Do the same kind of thing for the Y_Axis.

    Your chart is complete. OK your way out of the setup. Now when you select a number in cell B1, you will get the chart for that line of data.
    Attached Files Attached Files
    Last edited by dflak; 01-30-2016 at 05:50 PM.

  3. #3
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Button Macro to Recreate Graph With New Y-axis Values

    Thank you very much for your response. I apologize for not being quite clear enough but you guessed correctly to fill in the missing information. I didn't even consider named ranges. Now I will try to write a VBA script to automatically find and select the fields and recreate this procedure for the numerous sheets we have to analyze.

+ 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. Macro to set graph Y axis max and min equal to that of existing graph in worksheet
    By mm671750 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2015, 01:18 PM
  2. code to recreate graph 3 times
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2015, 12:05 AM
  3. Cant recreate a simple graph
    By Scarfer Brad in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-22-2013, 07:10 PM
  4. Replies: 0
    Last Post: 02-04-2013, 01:18 AM
  5. How do i recreate this graph
    By Selwof in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 09-09-2009, 12:28 PM
  6. How do i recreate this graph
    By Selwof in forum Excel General
    Replies: 1
    Last Post: 09-09-2009, 08:21 AM
  7. Link Chart Axis Scale Parameters to Values in Cells via Macro or Button
    By Ronald de Vries in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-22-2005, 08:10 AM

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