Finding the value of the first / last elements in an array

JR_Chicago

New Member
Joined
Apr 20, 2010
Messages
23
I have 10 one-dimensional arrays of numerical values, each of which contains 10 elements...

I have declared the arrays as Variants and have assigned ranges of cells to the arrays as follows:

array1 = Worksheets("Sheet1").Range("B2:K2").Value
array2 = Worksheets("Sheet1").Range("B3:K3").Value

etc etc...

I want to find the values for the first and last elements in these arrays but am having trouble writing the code to do so.

I read about the LBound and UBound functions but when I use those the value that is returned is "1" in both cases.

I've tried:

array1First = array1(1)
array1Last = array1(10)

Thinking that in an array with 10 elements, that such a convention would work but I just get an error message...

Also, I am trying to construct a one-dimensional array with 8 elements, each of which is a numerical value.

For this array, there is no range within the worksheet where the values are contained which I can assign to the array, rather, the array will contain the first & last elements in another array, as well as the mean, median, mode, etc of another array. I've written:

Dim statArray1(8) As Double

statArray1(1) = array1Mean
statArray1(2) = array1Median
statArray1(3) = array1Mode
statArray1(4) = array1First
statArray1(5) = array1Max
statArray1(6) = array1Min
statArray1(7) = array1Last
statArray1(8) = array1Range

In hopes of assigning array1Mean, array1Median, etc to the 1st, 2nd, etc elements in the array, however when I print statArray1 to my worksheet, zeros are populated where I'd hoped to see the stats I assigned to the array. I know the stats are being calculated properly so it must be the way I am assigning them to the array.

Any suggestions would be much appreciated!

Thanks a million!
 
Last edited:
You are right... I think this may be because the construction of these statArrays in carried out in a different subroutine than the subroutine where array1Mean, array1Median, etc are created...

I thought making the sub a "Public Sub" would allow me access to constants I'd created in other subroutines...

How to handle this?
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I thought making the sub a "Public Sub" would allow me access to constants I'd created in other subroutines...

No, "Public Sub" allows you to access the Sub, not the internal variables/constants.

Can you post your code?

Include the all the relevant declarations (Sub/Function/variables/constants), and the relevant code, for example that deals with statArray1 and array1Mean.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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