Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using LinEst function within VBA macro

I'm trying to perform a LinEst calculation (best fine line) within a VB
macro so I can use the resulting slope value for some othe
calculations.

As best as I can tell, I should be setting it up like this:

Code
-------------------
Value = Application.WorksheetFunction.LinEst(A1:A10,C1:C10
-------------------
However, when I try to compile this function, I get the followin
error:

Code
-------------------
Compile error:

Expected: list separator or
-------------------
I tried enclosing the ranges with quotes, but that didn't work either.
I could create a cell with the LinEst function in it then copy th
value, but that seems like a rather inefficient way for doing it.

Does anyone have an idea of how to make it work

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using LinEst function within VBA macro

Dim vValue as Variant
vValue =
Application.WorksheetFunction.LinEst(Range("A1:A10 "),Range("C1:C10"))

I didn't check your syntax, but as a minimum, you need to use range object
where you would use ranges in Excel.

I have posted serveral examples of using LinEst in VBA in the past. Search
google groups for examples.

http://groups.google.com/advanced_group_search?hl=en

--
Regards,
Tom Ogilvy

"RyanVM " wrote in message
...
I'm trying to perform a LinEst calculation (best fine line) within a VBA
macro so I can use the resulting slope value for some other
calculations.

As best as I can tell, I should be setting it up like this:

Code:
--------------------
Value = Application.WorksheetFunction.LinEst(A1:A10,C1:C10 )
--------------------
However, when I try to compile this function, I get the following
error:

Code:
--------------------
Compile error:

Expected: list separator or )
--------------------
I tried enclosing the ranges with quotes, but that didn't work either.
I could create a cell with the LinEst function in it then copy the
value, but that seems like a rather inefficient way for doing it.

Does anyone have an idea of how to make it work?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using LinEst function within VBA macro

OK, that gets me on the right track. What you posted works fine if yo
have a predefined range, however, I'm trying to set up a variabl
range.

I've tried the below code, but I get an error message
Code
-------------------
Slope = Application.WorksheetFunction.LinEst(Range("C" & MinRow & ":C" & MaxRow), Range("B" & MinRow & ":B" & MaxRow)
-------------------

Code
-------------------
Run-time error '1004'

Unable to get the LinEst property of the WorksheetFunction clas
-------------------
Any ideas

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using LinEst function within VBA macro

I tested in the immediate window:

Minrow = 3
maxrow = 11
Slope = Application.WorksheetFunction.LinEst(Range("C" & MinRow & ":C" &
MaxRow), Range("B" & MinRow & ":B" & MaxRow))
? isarray(slope)
True
? slope(1)
10
? slope(2)
-18.3333333333333

Couldn't reproduce a problem.

if you just want the slope, why not use the Slope WorksheetFunction

? Application.WorksheetFunction.Slope(Range("C" & MinRow & ":C" & MaxRow),
Range("B" & MinRow & ":B" & MaxRow))
10



--
Regards,
Tom Ogilvy

"RyanVM " wrote in message
...
OK, that gets me on the right track. What you posted works fine if you
have a predefined range, however, I'm trying to set up a variable
range.

I've tried the below code, but I get an error message.
Code:
--------------------
Slope = Application.WorksheetFunction.LinEst(Range("C" & MinRow & ":C" &

MaxRow), Range("B" & MinRow & ":B" & MaxRow))
--------------------

Code:
--------------------
Run-time error '1004'

Unable to get the LinEst property of the WorksheetFunction class
--------------------
Any ideas?


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using LinEst function within VBA macro

Note that this could be a data problem. In the worksheet, Linest would show
#Value or #Ref as an example. When you use WorksheetFunction as a
qualifier, it will raise an error such as you cite.

If you just qualify it with Application, it will raise a soft error you can
text for.

Dim slope as Variant
Dim maxrow as long, minrow as long
maxrow = 11
minrow = 3
Slope = Application..LinEst(Range("C" & MinRow & ":C" & _
MaxRow), Range("B" & MinRow & ":B" & MaxRow))
if iserror(slope) then
Select Case slope
Case CVErr(xlErrDiv0)
MsgBox "#DIV/0! error"
Case CVErr(xlErrNA)
MsgBox "#N/A error"
Case CVErr(xlErrName)
MsgBox "#NAME? error"
Case CVErr(xlErrNull)
MsgBox "#NULL! error"
Case CVErr(xlErrNum)
MsgBox "#NUM! error"
Case CVErr(xlErrRef)
MsgBox "#REF! error"
Case CVErr(xlErrValue)
MsgBox "#VALUE! error"
Case Else
MsgBox "This should never happen!!"
End Select
Else
msgbox "Slope is " & slope(1)
End If

--
Regards,
Tom Ogilvy




"RyanVM " wrote in message
...
OK, that gets me on the right track. What you posted works fine if you
have a predefined range, however, I'm trying to set up a variable
range.

I've tried the below code, but I get an error message.
Code:
--------------------
Slope = Application.WorksheetFunction.LinEst(Range("C" & MinRow & ":C" &

MaxRow), Range("B" & MinRow & ":B" & MaxRow))
--------------------

Code:
--------------------
Run-time error '1004'

Unable to get the LinEst property of the WorksheetFunction class
--------------------
Any ideas?


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using LinEst function within VBA macro

Nevermind, I figured it out. As they say, location is everything. I ha
it in a point in the macro where the range I wanted to perform a LINES
on didn't exist yet

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deriving P-Value through LINEST Function RJ Excel Worksheet Functions 2 May 2nd 23 03:46 AM
linest function for curve Baffeled Excel Discussion (Misc queries) 2 February 4th 09 01:18 PM
LINEST Function mcduffcpa Excel Discussion (Misc queries) 5 January 5th 09 07:26 PM
Linest function Barna Excel Worksheet Functions 1 February 16th 07 11:43 PM
LinEst function Darius Blaszijk Excel Programming 3 June 10th 04 03:12 AM


All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"