Hi Barry,
First, a small error in the code here:
The Cells properties need to be qualified in the same way as the Range property, otherwise, assuming your code is in a standard code module and if Sheet1 is not the active sheet, you will get an error.
Since num is 7 in your example, the range you are picking up the values from is Sheet1!B9:G9. If, as in this case, the range is more than one cell, then you will get a two dimensional array of values. Illustration:
The syntax of the LBound (and UBound) functions is as follows:
Originally Posted by
VBA helpfile
LBound(arrayname[, dimension])
dimension
Optional; Variant (Long). Whole number indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed
In your code you are using this:
So you are omitting the optional dimension parameter, thus it is assumed you want to return the lower or upper bound from the first dimension. As previously mentioned, the range you are picking the values from is Sheet1!B9:G9, so your tmparr variable actually has these dimesions once the values are assigned to it:
It is the second dimension you want to view the Lower and Upper bounds from so, in this particular case, you would want:
Bookmarks