+ Reply to Thread
Results 1 to 18 of 18

Regression Macro

  1. #1
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Regression Macro

    I have been reading around the forum trying to figure out the solution to this, but was unable to, so I thought I would join and post!

    I am doing cash projections for work, and I use a regression to do them. I want to make this work via macro in order to avoid doing it every month. I would like to have my Macro use a Y and X range that automatically goes to the bottom of the data (i.e. Month 1 to row 54, month 2 to row 55, etc. or wherever the end of the data happens to be)

    The regression output needs to have "labels" checked.

    My X and Y values come from the worksheet called "Regression Data"
    The Y data is currently C1:C54
    The X data is currently D1:S54
    (Rows will be added to these columns each month)

    The output is on the worksheet "Regression Output"
    The Output range is just this entire worksheet. (1:1048576)

    I attempted to simply record the macro, but kept getting errors about having no "Y" data, and when I looked at the code, I was unable to fix this and it did not appear that the macro was recording my input of the data range.

    I am not sure if this will happen automatically, but the new regression (ran via macro) needs to simply replace the old macro (i.e. go right on top of it, with the same data in the same cells)

    I will post my code below, if anyone is able to help me out with this. I would greatly appreciate it! Thank you!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Regression Macro

    it would be useful to see the dummy workbook otherwise it will look like treating patient by foto

  3. #3
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by watersev View Post
    it would be useful to see the dummy workbook otherwise it will look like treating patient by foto
    Would you like just screen shots of essentially what it would look like? Or is there a good way to post an actual excel file?

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Regression Macro

    Its better to attach a working copy of the workbook and what it is you want your outcome to be. Screenshots are not very helpful.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  5. #5
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by Mordred View Post
    Its better to attach a working copy of the workbook and what it is you want your outcome to be. Screenshots are not very helpful.
    I use excel 2007 at work, but have 2010 at home. I will set up a dummy worksheet in 2010 here and post it shortly.

  6. #6
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Here is what I just put together quick with the data and the output, basically what I want the Macro to do is the regression output in the same spot every time.

    I want it to automatically go to the bottom of the data in the y and x columns wherever that may be each month, if that is possible.

    The regression on this probably makes no sense as I made up numbers, but it is the same concept.

    Thank you again for all of the help!

    Dummy Regression.xlsx

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Regression Macro

    it's nice start to see the data structure. The only thing left is to understand what and how to do with the help of your explanation. I'm for example do not do regression analysis every day. The file has no either your macro nor formulas.

  8. #8
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by watersev View Post
    it's nice start to see the data structure. The only thing left is to understand what and how to do with the help of your explanation. I'm for example do not do regression analysis every day. The file has no either your macro nor formulas.
    I eventually want to create a button for it, so that after you have added new data to the spreadsheet (Regression Data), clicking the button will run a new regression using that new data (if possible) and put the output values where the previous regression output (Regression Output) was on the worksheet.

    When I tried to simply record the macro, it wasn't reading what the data parameters I was setting were. I am unsure why? Or how I could just write the code for it to do this?

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Regression Macro

    recording macro of all actions you are doing will be not bad

  10. #10
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by watersev View Post
    recording macro of all actions you are doing will be not bad
    That is what I originally tried, but it was not picking everything I was doing up.

    I would record the Macro, and when I went to run it, got the following error:

    "Regression - Input Y Range Missing. Please Enter"
    Last edited by Scher215; 12-23-2010 at 03:26 PM.

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Regression Macro

    i'm afraid it would be extremely difficult to help you unless you provide your actions and formulas you use. Namely what do these headers stay for: Coefficients Standard Error t Stat P-value Lower 95% Upper 95% Lower 95.0% Upper 95.0%
    How do you get those results? Is the calculation is the same for all rows? What are the formulas?

  12. #12
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by watersev View Post
    i'm afraid it would be extremely difficult to help you unless you provide your actions and formulas you use. Namely what do these headers stay for: Coefficients Standard Error t Stat P-value Lower 95% Upper 95% Lower 95.0% Upper 95.0%
    How do you get those results? Is the calculation is the same for all rows? What are the formulas?
    That is what the regression produces ... They are not formulas, that is the output that excel creates based on the data on the "Regression Data" tab. It is a Data-Analysis function that Excel does.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Regression Macro

    Are you interested in all of those stats or a subset?

    If you select K17:O33 on sheet regression input, paste

    =TRANSPOSE(LINEST('Regression Data'!C2:C49, 'Regression Data'!D2:S49,,TRUE))

    ... in the formula bar, and confirm with Ctrl+Shift+Enter, you'll see largely the same results, except that the order of the rows is reversed (a peculiarity of LINEST that I've never understood.)

    Specifically, coefficients are in the first col, and standard errors in the next (slightly different, but they are very small anyway).
    Last edited by shg; 12-23-2010 at 04:07 PM.
    Entia non sunt multiplicanda sine necessitate

  14. #14
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by shg View Post
    Are you interested in all of those stats or a subset?

    If you select K17:O33 on sheet regression input, paste

    =TRANSPOSE(LINEST('Regression Data'!C2:C49, 'Regression Data'!D2:S49,,TRUE))

    ... in the formula bar, and confirm with Ctrl+Shift+Enter, you'll see largely the same results, except that the order of the rows is reversed (a peculiarity of LINEST that I've never understood.)

    Specifically, coefficients are in the first col, and standard errors in the next (slightly different, but they are very small anyway.
    Nope, all I need are the coefficients. I will try out that formula and see how it works! Thanks.

  15. #15
    Registered User
    Join Date
    12-22-2010
    Location
    Minneapolis
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Regression Macro

    Quote Originally Posted by shg View Post
    Are you interested in all of those stats or a subset?

    If you select K17:O33 on sheet regression input, paste

    =TRANSPOSE(LINEST('Regression Data'!C2:C49, 'Regression Data'!D2:S49,,TRUE))

    ... in the formula bar, and confirm with Ctrl+Shift+Enter, you'll see largely the same results, except that the order of the rows is reversed (a peculiarity of LINEST that I've never understood.)

    Specifically, coefficients are in the first col, and standard errors in the next (slightly different, but they are very small anyway).
    That formula did exactly what I wanted! (Although the ordering of the coefficients is very curious as you mentioned)

    Is there a way, possibly with a macro, to have it so that when adding a new row (so that the data now goes down to C50 for example) to have the formula automatically now include that row? Or would I have to update the formula each time I add a row?

    Thanks!

  16. #16
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Regression Macro

    used Internet search, first link, as for me it's easier to make it manually or if not, see attachment
    Attached Files Attached Files

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Regression Macro

    See attached. I added dynamic ranges for X and Y so they adjust with new data, changed the constants in columns I:S to use a formula, and added a line of formulas to reverses the order of outputs of the LINEST function, so the coefficients appear above the relevant columns.

    Why does your data repeats every dozen rows?
    Attached Files Attached Files
    Last edited by shg; 12-23-2010 at 07:59 PM.

  18. #18
    Registered User
    Join Date
    08-18-2013
    Location
    San Diego
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Regression Macro

    Hey, Thanks from me as well. I was having the same problem, and this fixed it !

+ 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