View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ken Puls Ken Puls is offline
external usenet poster
 
Posts: 58
Default Transfer data from worksheet to array

Cheers, Tom. Thanks for the correction!

Ken Puls, CMA - Microsoft MVP (Excel)
www.excelguru.ca

Tom Ogilvy wrote:
You can use a variant to pick up the data in one go:

Sub aBC()
Dim v As Variant
Dim i As Long, j As Long
' Pick it up
v = Range("A1:Z15").Value
MsgBox "v is an array of 2 dimensions " & _
vbNewLine & _
"(1 to " & UBound(v, 1) & ", 1 to " & _
UBound(v, 2) & ")"

' Process it
For i = 1 To UBound(v, 1)
For j = 1 To UBound(v, 2)
v(i, j) = Int(Rnd() * i * j + 1)
Next
Next

'Put it down
Worksheets.Add After:=Worksheets( _
Worksheets.Count)
ActiveSheet.Range("B9").Resize(UBound(v, 1), _
UBound(v, 2)).Value = v


End Sub