ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Array-problem (https://www.excelbanter.com/excel-programming/283296-array-problem.html)

Tom

Array-problem
 
Hi

I'd like to read the values from a range into an array. Does anybody know,
how to make my example work?

Tom


Sub Test()
Dim aValues As Variant
Dim i As Integer

With ActiveSheet.Range("A1:A10")
aValues = .Value
End With

For i = 1 To UBound(aValues)
Debug.Print aValues(i)
Next i
End Sub



Leo Heuser[_2_]

Array-problem
 
Hi Tom

The created array will be a 2-dimensional one,
so in your situation with only one column use

For i = 1 To UBound(aValues,1)
Debug.Print aValues(i,1)
Next i

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Tom" skrev i en meddelelse
...
Hi

I'd like to read the values from a range into an array. Does anybody know,
how to make my example work?

Tom


Sub Test()
Dim aValues As Variant
Dim i As Integer

With ActiveSheet.Range("A1:A10")
aValues = .Value
End With

For i = 1 To UBound(aValues)
Debug.Print aValues(i)
Next i
End Sub





Dana DeLouis[_5_]

Array-problem
 
In addition to Leo, if you wish to keep it as a 1-Dim array, you could use
something like this:

Sub Test()
Dim aValues As Variant
Dim i As Integer

aValues = WorksheetFunction.Transpose(Range("A1:A10").Value)

For i = LBound(aValues) To UBound(aValues)
Debug.Print aValues(i)
Next i
End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Tom" wrote in message
...
Hi

I'd like to read the values from a range into an array. Does anybody know,
how to make my example work?

Tom


Sub Test()
Dim aValues As Variant
Dim i As Integer

With ActiveSheet.Range("A1:A10")
aValues = .Value
End With

For i = 1 To UBound(aValues)
Debug.Print aValues(i)
Next i
End Sub






All times are GMT +1. The time now is 09:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com