# Unable to get the correl property of the worksheet function class

#### Norie

##### Well-known Member
The values in ArrTemp are numbers and there are no errors in the series.
Have you checked all the values in ArrTemp in the Locals Window?

### Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

#### SBF12345

##### Well-known Member
when I run the test code against the worksheet correl function I get good numbers .35 and 65 for distance measure (1- correl) and the multiplier

#### SBF12345

##### Well-known Member
When I open the locals window I see ArrTemp as Empty. Following the ArrTemp variant back a bit I look at NumObs and ii, which both contribute to the variant PriceData.

NumObs is valued at 2 at the line:

Code:
``NumObs = UBound(X, 2)``
which I'm not sure I understand. I would expect a 12 to be the NumObs value because the locals window says X is "variant/variant(1 to 12, 1 to 2)

Why is NumObs returning a 2?

#### Norie

##### Well-known Member
UBound(X, 2) will return the upper bound of the 2nd dimension of X.

#### SBF12345

##### Well-known Member
The locals window reads X as type variant/variant(1 to 12, 1 to 2), shouldn't it be returning a 12?

#### SBF12345

##### Well-known Member
A is also returning a 2 on line

Code:
``A = UBound(PriceData,2)``

#### SBF12345

##### Well-known Member
I rewrote the lines defining A and NumObs to (changing the 2 to a 1)

Code:
``Dim A As Integer:                   A = UBound(PriceData, 1)     ' A is the population size and contains full set of test setsDim NumObs As Integer:              NumObs = UBound(X, 1)        ' NumObs is the sample size``
why would I receive different values for A and NumObs when the array data is 2 columns wide by 12 rows (in the case of NumObs) and 2 columns by 2800 rows(in the case of A).

After running here the code gets hung up on line and reads "out of range"

Code:
``TempSample(rr, 1) = PriceData(ii - rr + 1, 1)``
I also tested the first two lines using:

Code:
``````A = UBound(PriceData,0)
NumObs = UBound(X,0)``````
When I tried this the locals window gave no values for A or NumObs

What it looks like is that the initial array defined by lines:

Code:
``Dim PriceData As Variant:           PriceData = Worksheets(DataSht).Range(SampleRange)``
and

Code:
``Dim X As Variant:                   X = Worksheets(DataSht).Range(DataRange)``
isn't recognizing a second dimension despite the locals window reading "variant/variant(1 to a number, 1 to 2)"

#### Norie

##### Well-known Member
The locals window reads X as type variant/variant(1 to 12, 1 to 2), shouldn't it be returning a 12?
No, the first dimension (1 to 12) of X has a lower bound of 1 and upper bound of 12, the second dimension (1 to 2) of X has a lower bound of 1 and upper bound of 12.

UBound(X, 2) returns the upper bound of the second dimension of X.

The second argument of UBound determines the dimension for which you want the upper bound.

Last edited:

#### SBF12345

##### Well-known Member
the second dimension (1 to 2) of X has a lower bound of 1 and upper bound of 12.
Is there a type-o in this line? because when I run the code with Ubound(X,2) and Ubound(PriceData,2) I receive NumObs = 2 and A = 2. When I run the code with UBound(X,1) and UBound(PriceData,1) it returns A = 2801 and NumObs = 12. It looks like the UBound function is returning not the number of elements in the second dimension but the upper bound of the number of columns in X or PriceData.

#### Norie

##### Well-known Member
Yes there is a typo, it should read like this.
me said:
the second dimension (1 to 2) of X has a lower bound of 1 and upper bound of 2.
Note, UBound does not return the no of elements in an array.

1,095,201
Messages
5,442,997
Members
405,212
Latest member
Arnie58

### This Week's Hot Topics

• Copy entire row if CountA <>0 to another sheet
[B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
• Select last used Row in Table
I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
• excel workbook: do not allow certain file name
Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
• fixing problem autofilter
hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
• “Weight”
Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
• How to capitalize everything before a certain character?
In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...