+ Reply to Thread
Results 1 to 3 of 3

VBA to make charts for a certain X,Y ranges and export slope results

  1. #1
    Registered User
    Join Date
    06-28-2024
    Location
    Germany
    MS-Off Ver
    2021
    Posts
    21

    VBA to make charts for a certain X,Y ranges and export slope results

    Good day everyone,

    I am trying to use VBA to make charts based on certain ranges for X and Y axis from a dataset, and then calculating the slope and exporting the results in a respective cell in a table. I have attached a sample file with an example of what the final product sheet will look like. I tried to integrate information via text boxes, hopefully in a clear way.

    Your guidance and help is appreciated.

    Thank you!

    Regards,
    FNa
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,817

    Re: VBA to make charts for a certain X,Y ranges and export slope results

    I think, that instead of looking at parameters of trendline on the graph, it would be wiser just to calculate them.
    In Excel you have two functions to do it: SLOPE and INTERCEPT. And to select only part of the data by limits in D or B column you can use FILTER function (good that you have Excel 2021, because it was not available in earlier versions).

    And the limits shall be written in separate cells not as a range in one cell (see E4:F11 in attached file).
    for 1st case (cells H7 and I7) the formulas would be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and for H8:I8 and copied down for cases 2-5
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And as for Graphs - if you would like to have graps too not just calculations, I'd think of making them dynamic in a similar way as presented just few threads ago https://www.excelforum.com/excel-for...-is-blank.html

    You would need 10 names defined, 2 for each graph.

    Final comment - if for different datasets you have different number of data points, think of maximum possible number - formulas could be with "surplus rows", like

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    just make sure you edit all max rows to the same number.

    yet another ;-) final comment, of course you can use ROUND function and nest above formulas into it, to have results rounded to reasonable number of decimal places)
    Attached Files Attached Files
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    06-28-2024
    Location
    Germany
    MS-Off Ver
    2021
    Posts
    21

    Re: VBA to make charts for a certain X,Y ranges and export slope results

    Hi Kaper,

    thank you for the message. I have been trying with the name tags, but I get excel formula reference error and I also observed that, for some reason, the value "Refers to" in the name manager changes after this error.

    I also tried to use an indirect function and added the data ranges for x and y axis in the sheet, but still doesn't work.

    Bests
    Attached Files Attached Files

+ 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. Make Excel Charts Dynamic using Named Ranges
    By mchilapur in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-30-2019, 06:21 AM
  2. [SOLVED] Export charts and ranges from multiple worksheets to PPT presentation draft
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-30-2019, 06:05 AM
  3. [SOLVED] Problem with Slope Forumla results vs Graph results
    By melegaunt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-02-2015, 05:51 PM
  4. Linest/slope functions with with different data ranges
    By Pat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  5. [SOLVED] Linest/slope functions with with different data ranges
    By Jerry W. Lewis in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 07:05 AM
  6. [SOLVED] Linest/slope functions with with different data ranges
    By Pat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. Linest/slope functions with with different data ranges
    By Pat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 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