LinEst In Vba - Not Using Ranges
Nov 12, 2008
I am calculating variables in Vba and want to find their co=effiicients in the for y=a +bx +cx^2. This works great if I output my variables to excel and then pick up this range however as I am generating the variables in vba and have an array of variables I would rather not have to keep spitting them out to excel then picking them up again. The three important lines in my code are:
c(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(inpv, Application.Power(inps, Array(1, 2))), 1)
b(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(Range(Vc), Application.Power(Range(SPd), Array(1, 2))), 1, 2)
a(nFix - j) = WorksheetFunction.Index(WorksheetFunction.LinEst(Range(Vc), Application.Power(Range(SPd), Array(1, 2))), 1, 3)
As you can see for c I am referring to inpv and inps these are arrays. I have tried using inpv(), etc but no luck
b and a work great, here I am reffering to ranges Vc and SPd. As I am going through this a lot of times it seems rather inelegant not to be able to do the whole thing in vba - i would rather not use the dump to spreadsheet then pick up again approach!
View 9 Replies
ADVERTISEMENT
Jun 19, 2008
I have a table something like this (much bigger in reality)
1 5
2 10
5 15
7 #N/A
9 20
12 25
I need to interpret the above data with the linest function, but for a variety of reasons i cant delete the error square. How can i get the LINEST to ignore the #N/A and the 7? otherwise it returns an error.
View 14 Replies
View Related
Jan 22, 2009
I am using Excel 2007. I have two sets of data. y-series is 58.61, 58.66, 58.71 and 58.76. x-series is 0.8313, 0.8309, 0.8305 and 0.8301.
I am trying to fit a quadratic function to this data. When I plot a curve and fit a trendline I get the coefficients for the equation ax^2+bx+c
a=1.3939e-11
b=-125
c=162.5225
The plotted line seems to fit the data fairly well.
However, I want to use the linest function and I am using the formula:
=INDEX(LINEST(B2:B5,A2:A5^{1,2}),1,1)
I change the index column number as appropriate to get the coefficients:
a=-75.23775
b=0
c=110.603763
The coefficients from linest seem to be way out. how I can get the output from linest to be the same as the trendline?
View 4 Replies
View Related
Oct 23, 2008
My "calculated" polynomial is not the same as the Trend line on the graph. The one on the graph seems to be correct.
Basically, I am using the LINEST function to create a polynomial equation inorder to extrapolate data. And also with a given equation, and a given y, find x.
View 8 Replies
View Related
Feb 12, 2010
I'm trying to implement the linest formula in a programming language for my coursework.
I've looked on excel help but it only explains on how the function selects data.
how to the values are calculated and the steps?
View 14 Replies
View Related
Jun 23, 2014
is there a way to use LINEST in a way in which the x values are unknown and the y values are known? The opposite of how the function usually runs...?
View 2 Replies
View Related
Sep 2, 2008
how to get my LINEST function to work properly. Now, what I'd like to do is have it reduce or increase the order of the polynomial until R^2 equals 1.0, or the polynomial reaches 6th order, whichever comes first.
Can I do this with a bunch of nested IF ELSEIF statements, or is there a cleaner way to do this?
View 12 Replies
View Related
Dec 21, 2006
I am trying to obtain the 3 coeffs from a polynomial trendline equation.
The equation produced on the chart is
y = 3.1123x2 + 135.34x + 124.9 from the below info
X Y
1.0 250
2.5 500
5.0 890
7.5 1290
10.0 1800
But when I enter this array formula
{=LINEST(B2:B6,A2:A6^{1,2})}
I get different results.
-48.98,375.89,214.98
View 9 Replies
View Related
May 7, 2005
I can do least squares fitting utilizing LINEST and a worksheet. (See attachment.)
I would like to do the same calculations entirely within VBA.
I can specify the values as arrays within VBA :
Sub linest2VBA()
'
' linest2VBA Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Dim dXvalSqd(4), dXval(4), dYval(4), dFirstRegStat As Double
Dim i As Integer
Second Question:
Is there a way to get the remaining regression statistics within VBA by referencing only the three arrays: dXvalSqd, dXval, and dYval?
View 3 Replies
View Related
Apr 27, 2009
I need to know how to selec no-adjacent columns for the known_x's in the linest function:
Example:
'- A B C D E
1) 80 63 9 3 26
2) 80 63 9 3 21
3) 74 65 7 2 30
4) 74 65 7 2 20
5) 63 65 9 3 16
=LINEST(A1:A5,KNOW_X'S,TRUE,TRUE)
Is there any way to select for instance: column B and E as known_x's?
I heard about something where we can select total area and then choose which columns should be considered via "{column1, colum2}"..
That is all is missing for me to finish my project!!! Pls your help!!!
View 6 Replies
View Related
Mar 1, 2012
I have built a user defined function called: portAlpha.
Code:
Function portAlpha(assetCode As String, indexCode As String) As Double
Dim assetCol As Long
Dim indexCol As Long
Dim assetData As Range
Dim indexData As Range
With Sheets("Data")
[Code] ......
I am struggling to get this to work though. Everytime I step over this piece of code:
Code:
portAlpha = Application.WorksheetFunction.LinEst(Range("M4:M63"), Range("N4:N63"), 1, 1)
I get a "Type Mismatch Error". All the values in the range are numbers, and LINEST should return a double, so I am puzzled as to why there is a mismatch...
I have hardcoded the range into the formula just to try and get it to work. Eventually this will be two variables and will look like this:
Code:
portAlpha = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(assetData, indexData, 1, 1),1, 1)
View 1 Replies
View Related
Jan 13, 2010
I am trying to use the LinEst function in a program. There are some good examples on the web but they all refer to a range in the format “A1:A45”. Is there a way to refer to a column in an existing array instead?
For example (thanks to Shg for this code): ....
View 7 Replies
View Related
Dec 31, 2007
I have set up regression in excel using the linest array function which automaticly updates whenever the data it is references changes. Currently the formula in K3 =
=LINEST(K8:K50,M8:N50,TRUE,TRUE) .
Only the Y range in column K changes and then the formula automaticly recalculates the regression parameters. However sometimes the range of valid data changes with each new update so currently K8 to K50 contains valid values and so the formula works. But if the range of valid data now ends at say K45, and the remaining rows (K46- K450) contains #DIV/0!. In this case the formula does not work and I need to go in manualy into K3 and reselect the range to get it to work (in the baove case to =LINEST(K8:K45,M8:N45,TRUE,TRUE)
Is there anyway I can get the formula to update the range (the number of rows to use) in the calculation automaticly so I don't have to go into the formula in K3 and change the range manually everytime the data changes? Basicly I like to use all rows in column K (from K8 to K50) where there is a values and ignore cells with #DIV/0!
I'm guessing the easiest way to do this would be to set up a dynamic range of some sort that feeds into the linest array function so that the end row reference for columns K and M & N changes depending on where the first #DIV/0! occurs in column K.
View 9 Replies
View Related
Sep 4, 2009
I have instances where my Y variables sometimes contain a zero in the data and i need a formula to skip over that data point in the LINEST calculation.
Y variables are in Row 1, Columns A:E
X variables are in Row 2, Columns A:E
The following formula is returning a #VALUE! error: .....
View 9 Replies
View Related
Mar 2, 2009
I'm using Excel 2003 and I'm trying to make my LINEST function and the source cells for a scatter graph use the cell range specified in another cell in the document. I figured out that it was simple to do the following:
I250 contains: 10, shows: 10
I251 contains: ="I"&I250, shows I10
But I can't figure out how to do this in a larger function. I've tried a few things but none of them work. Here is an example where I want it to do a LINEST with y values in cells Ja - Jb and x values in cells Ia - Ib (where a and b are integers specified in cells I250 and J250 respectively):
View 9 Replies
View Related
Oct 25, 2007
I need help creating a macro that will search through my excel spreadsheet and for every instance where column A isn't empty it should cut a range of columns from that row and paste them in a different range of columns in the row before it. It should then delete the row that it cut the columns from and keep searching until it has done this for the whole worksheet. I can modify which range of columns are needed, but it has been so long since I've worked with excel macros that I haven't been able to do it.
View 5 Replies
View Related
Feb 26, 2010
definitions for static ranges and dynamic ranges?
View 9 Replies
View Related
Mar 7, 2013
I have two vertical ranges that I need summarized into 2 adjacent vertical ranges.
"
A B C D
| SUMMARY
model qty| modelqty
1 4.12922.0000| 4.12952.2000
2 2.000012.1250| 2.000025.1250
3 4.12929.0000| 318.0000
4 318.0000|
5 4.1291.2000|
6 213.0000|
"
A1:A6 is my SKU's model number B1:B6 is my inventory C1:C6 should contain formulas that result in a summary of the models D1:D6 should contain formulas that result in a sum of the inventory count for each model
View 1 Replies
View Related
Nov 1, 2006
In the attached file, I have variable range in column A:B, column C:D and in column E:F
I want a macro to do the following:
Start with sheet "A", select the available range in column A
then copy and paste in the sheet "B" but with all the cell values added with the value in H1.
Then in sheet A, simply copy the available range in column B and paste it in sheet B
Do the same until column F in sheet A. Pastespecial if it is odd column. simple past it is even column.
I know the macro code for the simple paste. But I am struggling with the paste special code.
View 9 Replies
View Related
Apr 28, 2014
I have written this macro to convert into a csv file to run for all defined named ranges in the activesheet. It run jst perfect when I hit SAVE button and it creates that many different CSV files for each named range.
However I am trying to use same macro in the another file and the problem I am facing is there a lot more named ranges and I want to run the macro for only selected NAMED RANGE. In this case 2 Named Range / 24 Named range.
What part of code do I need to change and to what to make it work for just 2 named ranges ?
View 6 Replies
View Related
Jan 11, 2010
I am trying to locate a named range cell in my VBA macro, but find that VBA will only allow me to specify the actual cell eg. Range("E2").
The piece of code I am using below is
Sheets("sheetname").Select
Range("E2").End(xlDown).Offset(1, 0).Select
I would like to use
Range("namerange").End(xlDown).Offset(1, 0).Select
Do i need to Dim or specify the name range in any particular way.
View 9 Replies
View Related
Oct 14, 2006
I'm trying to get a formula to give and yes or no answer if a cell is between two numbers.
Example: Cell AB9 = 100.2 in cell AB11 would be a formula that would answer "Yes" because it is between 96.8 and 100.4. Any number outside this range would answer "No."
View 3 Replies
View Related
Sep 15, 2014
I am trying to make a UDF that searches for a header, grabs everything under the header, and pulls it somewhere else. My UDF has three parameters:
1) Output_Range: the named range where the parameters will be pulled to
2) Header: the header to search for in order to copy the data underneath it
3) WorkbookName: the name of the workbook to search in
It looks like this:
VB:
Function LoadParameters(Output_Range As Range, Header, WorkbookName As String)
MyTimer = Timer
'Defining the variables.
Dim HeaderCell, HeaderCellEnd, HeaderRange, Output_Range
[Code]....
View 3 Replies
View Related
Nov 5, 2008
I'm attempting to do a sumproduct with different dimensioned ranges. I've read multiple posts that say that all ranges in a sumproduct must have the same dimensions. I've tried different commands (index/match/lookup, etc) with no luck. Perhaps someone can come up with a solution for me....
View 7 Replies
View Related
Feb 1, 2014
I have set following ranges:
[Code] ....
I use above rngData1 as follows:
[Code] ....
How can I use all above ranges in For Each statement?
For example For Each rngRow In .Range(rngData1+rngData2+rngData3+rngData4).Rows
View 3 Replies
View Related
Feb 3, 2014
I'm trying to create a Formula where the User has to select 2 Ranges and then a calculation is done for each corresponding cell.
I thought about using arrays or ranges but I'm quite lost.
[Code] ....
My Second approach would be to use Arrays
[Code] .....
This is what I thought about so far but it does not work. I guess because I have to Idea how to tell VBA to use the Interestrates Range for each corresponding cell.
View 3 Replies
View Related
Mar 9, 2014
In sheet x the range("d2:d20") will change from time to time. I've created a button that should copy this range("d2:d20") to sheet called summary and there to the next empty column. So the variable lstcol (dim = long) is the last empty column in summary. I'm definitely not using properly the range method.
View 8 Replies
View Related
Aug 28, 2008
I have 2 ranges with values, and I want to use countif to see of there's a same value in each of these ranges.
View 9 Replies
View Related
Oct 18, 2008
I would like to perform a calculation with each cell in a range from 2 worksheets and place the result in a range on a third worksheet.
I thought I could use the For Each Cell in Range construct but I don't see how to reference the two ranges in a nested pair of For loops. I am sure there must be an simple/elegant way to do this.
View 7 Replies
View Related
Oct 21, 2008
I have a macro that has automated 95% of a task but one thing is still evading me! If I use the keys then this is what I do:
Select cell C192
Select Shift and R-Arrow so that C192 and D192 are selected
Select Ctrl, Shift and Up Arrow so that C1:D192 are selected
Select Shift and Down Arrow so that C2:D192 are selected
View 8 Replies
View Related