R
rwjack
I am trying to improve my coding skills in Excel VBA and I just can't seem to
find a good, very basic, example of how to use a 2-dimensional array. I've
looked in several reference books & browsed VBA Forums but can't find an
example I can understand. What I was trying to do was define a 3 x 4 Array
that has a data type of Single. My sample data is located in Cells E1:H3.
E F G H
1 3.4 8.1 11.6 100.3
2 5.2 7.3 45.2 632.4
3 1.7 9.6 39.7 161.5
I've been trying to use the LBound and UBound functions too, thinking this
might be the best approach but none of my coding attempts work. That is why I
did not include any.
I would like to be able, using code, see what is in each Array element and
then be able to Sum the values and see the results in a variable.
I was able to create a 1-dimensional Array, shown below, but it is pretty
basic.
Sub SampleArray()
Dim Data(9) As Single
Dim i As Integer
Dim cum As Single
For i = LBound(Data) To UBound(Data)
Data(i) = Cells(i, 1)
MsgBox prompt:=Data(i)
cum = cum + Data(i)
MsgBox prompt:=cum
Next i
End Sub
I would appreciate any help submitted. Thanks
find a good, very basic, example of how to use a 2-dimensional array. I've
looked in several reference books & browsed VBA Forums but can't find an
example I can understand. What I was trying to do was define a 3 x 4 Array
that has a data type of Single. My sample data is located in Cells E1:H3.
E F G H
1 3.4 8.1 11.6 100.3
2 5.2 7.3 45.2 632.4
3 1.7 9.6 39.7 161.5
I've been trying to use the LBound and UBound functions too, thinking this
might be the best approach but none of my coding attempts work. That is why I
did not include any.
I would like to be able, using code, see what is in each Array element and
then be able to Sum the values and see the results in a variable.
I was able to create a 1-dimensional Array, shown below, but it is pretty
basic.
Sub SampleArray()
Dim Data(9) As Single
Dim i As Integer
Dim cum As Single
For i = LBound(Data) To UBound(Data)
Data(i) = Cells(i, 1)
MsgBox prompt:=Data(i)
cum = cum + Data(i)
MsgBox prompt:=cum
Next i
End Sub
I would appreciate any help submitted. Thanks