View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default Using Regression Function in VBA Macro


"Shreyans Jain" wrote in message

Hi,

I wanted to use the regression functionality of Excel in a VBA code to
use it on specific data which has more than one independent variables
entered by the user but I haven't been able to find the correct syntax
to be used to call the function. I know it is something related to
"ATPVBAEN.XLAM!Regress" or something but if somebody could give me the
correct syntax with all the options like plot, etc then that would be
really helpful.

I specifically need to make a VBA project out of it so using the addin
manually is of no use to me, I wish to call the functionality from my
VBA code to make it automatic for the user. Please let me know the exact
syntax of this function.


These are the arguments

Regress(inpyrng, inpxrng, constant, labels, confid, soutrng, residuals,
sresiduals, rplots, lplots, routrng, nplots, poutrng)

Apart from the first Y-input range argument the others are optional. Call
like this

Application.Run "atpvbaen.xlam!regress", Range("B2:B19"), Range("A2:A19")

It's easier, particularly in development, to set a reference in tools/refs
to atpvbaen.xla, then you can simply use Regress as if it was a builtin
function and get the intellisense, simply

regress Range("B2:B19"), Range("A2:A19")

It's not always practical to keep the reference when distributing, if in
doubt remove it and use the app-run method

In Excel, Data, Analysis data (at the end), Data Analysis, Regression (OK)

Take a screen shot of the dialog (alt-prtScn) and paste it on a sheet. You
should be able to recognise the Regress arguments on the dialog.

You could build your own form along the lines of the dialog, with
inputbox's, refedit's etc for user to pick and apply the inputs.

Compare your results with the builtin results.

There's also RegressQ though I'm not sure what the difference is.

Regards,
Peter T