LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Reading data into a 2 dimensional array

Hi Keith,

I think that unlike normal arrays, if you test you will find that both
methods are 1 based by default. Try out the following examples.

Sub RngToArray()

Dim myArray As Variant
Dim Low1 As Long
Dim Upp1 As Long
Dim Low2 As Long
Dim Upp2 As Long
Dim i As Long
Dim j As Long

myArray = Sheets("Sheet1").Range("A1:D4")

'Lowest element in first dimension
Low1 = LBound(myArray, 1)

'Highest element in first dimension
Upp1 = UBound(myArray, 1)

'Lowest element in second dimension
Low2 = LBound(myArray, 2)

'Highest element in second dimension
Upp2 = UBound(myArray, 2)

MsgBox "Low1 = " & Low1 & vbCrLf & _
"Low2 = " & Low2 & vbCrLf & _
"Upp1 = " & Upp1 & vbCrLf & _
"Upp2 = " & Upp2

For i = Low1 To Upp1
For j = Low2 To Upp2
MsgBox myArray(i, j)
Next j
Next i

End Sub


Sub RngToArray2()

Dim myArray As Variant
Dim Low1 As Long
Dim Upp1 As Long
Dim i As Long

myArray = Sheets("Sheet1").Range("A1:A4")

'Lowest element in first dimension
Low1 = LBound(myArray, 1)

'Highest element in first dimension
Upp1 = UBound(myArray, 1)

MsgBox "Low1 = " & Low1 & vbCrLf & _
"Upp1 = " & Upp1

'Note because assigned to variant you must
'use the first dimension in the formula
For i = Low1 To Upp1
MsgBox myArray(i, 1)
Next i

'Alternative using 1 as the first element
'For i = 1 To Upp1
' MsgBox myArray(i, 1)
'Next i

End Sub

Sub RngTest()

Dim myRng As Range
Dim i As Long
Dim j As Long

Set myRng = Sheets("Sheet1").Range("A1:D4")
For i = 1 To 4
For j = 1 To 4
MsgBox myRng(i, j)
Next j
Next i


End Sub

--
Regards,

OssieMac


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading data into a 2 dimensional array Under Pressure Excel Programming 3 January 11th 10 10:13 PM
Reading data into a 2 dimensional array Under Pressure Excel Programming 1 January 11th 10 09:00 PM
Export 1-dimensional array values to a two-dimensional table? Laurie Excel Programming 2 November 8th 07 03:51 PM
How to generate formula from two dimensional array of data KROATA Excel Worksheet Functions 1 December 2nd 05 12:39 PM
sort multi-dimensional array on numeric data? RB Smissaert Excel Programming 0 July 14th 03 10:49 PM


All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"