View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
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/