Syntax error in defining range using a worksheet function

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am receiving a compile error on this line:

Code:
h = worksheetfunction.Slope((Cells(yy,ww):Cells(2,ww)),(Cells(yy,xx):Cells(2,xx)))

the first colin in the Y's range is highlighted. What is the correct syntax here again?

Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
h = WorksheetFunction.Slope(Range(Cells(yy, ww), Cells(2, ww)), Range(Cells(yy, xx), Cells(2, xx)))
 
Upvote 0
Thanks!

With the same line I am receiving a compile error: invalid qualifier with ".Slope" highlighted.

I looked over the variable types and I think they are ok. What else might be causing this?
 
Upvote 0
Upvote 0
I think I figured it out:

Code:
zh = Workbooks("COMM_PA.xls").Worksheets(zz).WorksheetFunction.Slope(Range(Cells(yy, zb), Cells(2, zb)), Range(Cells(yy, za), Cells(2, za))).Value

PS I changed some variables.

Thanks footoo
 
Upvote 0
I am still hung up on this line,

The current code looks like:

Code:
With Workbooks("COMM_PA.xls").Worksheets(zz)

zh = WorksheetFunction.Slope(Range(Cells(yy, zb), Cells(2, zb)), Range(Cells(yy, za), Cells(2, za))).Value

And I am receiving an "invalid qualifier compile error" on the line beginning with zh. Also, "Slope." is highlighted.
 
Upvote 0
Here is more of the code earlier in the script:

After looking around online a bit the problem may be due to the nature of the range values and how the ranges are defined. I do use a few variable types in ultimately defining the column values for the Cells(r,c) portion of the Range in worksheetfunction.slope

Code:
    Dim ws As Worksheet
Dim za As String
Dim zb As String
Dim zc As String
Dim zz As String
Dim xx As Variant
Dim ww As Variant
Dim zj As Integer
Dim zh As Long
Dim zi As Integer
Dim yy As Integer


Dim col As New Collection
Dim col2 As New Collection


col.Add "b"
col.Add "c"
col.Add "D"
col.Add "E"
col.Add "F"
col.Add "G"
col.Add "h"
col.Add "i"
col.Add "j"
col.Add "k"
col.Add "l"
col.Add "m"
col.Add "n"
col.Add "o"
col.Add "P"
col.Add "Q"
col.Add "R"
col.Add "S"
col.Add "T"
col.Add "U"
col.Add "V"
col.Add "W"
col.Add "x"
col.Add "y"
col.Add "z"
col.Add "AA"
col.Add "AB"
col.Add "AC"
col.Add "AD"
col.Add "AE"
col.Add "AF"
col.Add "AG"
col.Add "AH"
col.Add "AI"
col.Add "AJ"
col.Add "AK"
col.Add "AL"
col.Add "AM"
col.Add "AN"
col.Add "AO"
col.Add "AP"
col.Add "AQ"
col.Add "AR"
col.Add 45
col.Add "AT"
col.Add "AU"
col.Add "AV"
col.Add "AW"
col.Add "AX"
col.Add "AY"
col.Add "AZ"
col.Add "BA"
col.Add "BB"
col.Add "BC"
col.Add "BD"
col.Add "BE"


col2.Add "BF"


For Each ws In Workbooks("COMM_PA.xls").Worksheets


zz = ActiveSheet.Name


yy = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


For Each xx In col


za = xx


For Each ww In col2


zb = ww


With Workbooks("COMM_PA.xls").Worksheets(zz)


zh = Application.WorksheetFunction.Slope(Range(Cells(yy, zb), Cells(2, zb)), Range(Cells(yy, za), Cells(2, za)))


zc = Workbooks("COMM_PA.xls").Worksheets(zz).Range(Cells(1, zb)).Value & " " & Workbooks("COMM_PA.xls").Worksheets(zz).Range(Cells(1, za)).Value


zi = Workbooks("COMM_PA.xls").Worksheets(zz).WorksheetFunction.RSq(Range(Cells(yy, zb), Cells(2, zb)), Range(Cells(yy, za), Cells(2, za))).Value


End With
 
Upvote 0
Slope returns a value, not an object with a Value property. Try:

Code:
With Workbooks("COMM_PA.xls").Worksheets(zz)

zh = Application.WorksheetFunction.Slope(.Range(.Cells(yy, zb), .Cells(2, zb)), .Range(.Cells(yy, za), .Cells(2, za)))
End With
 
Upvote 0
apologies for posting so frequently without follow up responses, but I have new information that may be significant in solving the error.

Using the add watch feature I see that my collection values are report as "b", "c", "d", etc including the quotation marks. variables zb and ww also look OK using the add watch value function. the cells(yy,zb) value as observed with add watch reads error 2007. Not sure what this is.

Specifically, the variable zb (a string) is defined using ww (a variant) which is a variable used in stepping through the collection. I suspect the variables used in declaring the range are giving trouble.
 
Upvote 0
Thanks RoryA,

I tried running it with the changes described in your post but still received the "unable to get the slope property of the worksheetfunction class" runtime error.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top