+ Reply to Thread
Results 1 to 13 of 13

Automatically change graph axis range according to data in cells

  1. #1
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Automatically change graph axis range according to data in cells

    Hello – I am using both Excel 2007 and 365. I am developing some spreadsheets for quality assurance of medical equipment. These sheets are to determine the baseline values of the equipment and the operator; after 20 - 25 sets of data are collected, the means, SD and CoVar will be used for ongoing quality assurance. During baseline data collection, the scaling of the Levy-Jennings graphs needs to change to reflect to the collected data. I would like these graphs to autoscale to +/- 4 SD from the mean. Setting these graphs in Excel to autoscale usually results in too large a range on these graphs; I'd like better resolution than this. Is it possible for the axis setting to look to cells on the sheet (O5:P6) to set the lower and upper limits of the graphs?

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Automatically change graph axis range according to data in cells

    AFAIK, not without using VBA.

    See sample I did a while ago. This uses PivotChart, but same concept applies to standard charts.

    Have a read of...
    https://peltiertech.com/link-excel-c...lues-in-cells/
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Re: Automatically change graph axis range according to data in cells

    Thank you, CK76. I've never learned VBA, and maybe it's time I did. Is it difficult to learn enough (for now) to do what I need to do? Can you recommend a good source I can learn VBA from?

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,880

    Re: Automatically change graph axis range according to data in cells

    For just this purpose, the link I gave you should be enough.

    For more in depth learning... check thread below for many resources available.
    https://www.excelforum.com/excel-pro...materials.html

    The way I learned, is by finding interesting challenge/project. Then use Google Search (especially Advanced Search), to find pertinent info and work on it one step at a time.
    I also used to download various sample files and reconstructed them from scratch to learn.

  5. #5
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Automatically change graph axis range according to data in cells

    Try something like (into HBS sheet code):

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  6. #6
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Re: Automatically change graph axis range according to data in cells

    Thanks again, CK76. Time for me to start reading up on this.

    Thank you, Kokosek. Is this the VBA "script" (or whatever it's called) to accomplish what I need to do? How would I insert this into my sheet?

  7. #7
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Automatically change graph axis range according to data in cells

    On excel press Alt+F11 then VBA window open.
    Find on left your workbook and paste as below:

    Capture.JPG

  8. #8
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Re: Automatically change graph axis range according to data in cells

    Hi, Kokosek.

    Sorry for the delayed response, I've been on the road. I'm currently away from my system with Excel 2016 and only have access to Excel 2007. From the screen print you posted, I can't figure out how to import the script you wrote into my Excel 2007 spreadsheet. Could you provide some instructions for this?

    Thanks very much.

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: Automatically change graph axis range according to data in cells

    right click the tab
    select view code
    paste the code you copied above
    Ben Van Johnson

  10. #10
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Re: Automatically change graph axis range according to data in cells

    Thank you, protonLeah, this was very helpful. With your instructions, I was able to paste Kokosek's script into my sheet.

    Kokosek, thank you VERY much! I'll still try to start learning VBA, but you saved me a lot of time by writing the script that I could use.

  11. #11
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Automatically change graph axis range according to data in cells

    Happy to help.

  12. #12
    Forum Contributor
    Join Date
    01-09-2009
    Location
    NJ/NY
    MS-Off Ver
    Excel 2007 & 2016
    Posts
    124

    Re: Automatically change graph axis range according to data in cells

    Hello, Kokosek.

    In September 2019, you had helped me with VBA for a quality control spreadsheet I've been working on. A problem I've encountered is this error message:

    Microsoft Visual Basic
    Run-time error '1004':
    Unable to get the Min property of the WorksheetFunction class

    In the error message window, there are buttons for End, Debug and Help.

    This message continues to appear with every data entry until there are two rows of data. I suspect the macro is "crashing" until there are enough data to calculate the standard deviations. Is there a way to modify the macro so this message doesn't appear?

    Thanks very much.

  13. #13
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Automatically change graph axis range according to data in cells

    Hi Jim (msg already sent on PW)


    Click Debug and error message window, then in VBE it will highlight in yellow error line. I suppose that will be one of them:

    Please Login or Register  to view this content.
    Check columns AO and AW. Maybe there are some errors or something that why excel can't calculate MIN values from this column.

+ 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. Replies: 1
    Last Post: 01-12-2018, 04:16 PM
  2. [SOLVED] Chart X-Axis Range Automatically Expanding With Selected Y-Axis Range
    By Mvaldesi in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 10-08-2015, 03:43 PM
  3. Setting graph axis to automatically reflect values in cells
    By RossN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2014, 11:57 PM
  4. Replies: 0
    Last Post: 03-21-2013, 05:26 AM
  5. [SOLVED] How to change graph axis name automatically?
    By NameUse in forum Excel General
    Replies: 3
    Last Post: 11-19-2012, 04:42 PM
  6. Automatically change axis number format on graph
    By wiseheak in forum Excel General
    Replies: 3
    Last Post: 07-11-2012, 10:16 AM
  7. Replies: 6
    Last Post: 01-25-2006, 02:45 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