Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reading data into a 2 dimensional array

My original post on this appears to have disappeared, so here goes again.

I want to do some complex analysis on some data in a spreadsheet. I would
like to use a macro but don't know how to 'read' the data from the
spreadsheet into a 2 dimensional array. Back in the old days of programming
in GWBASIC, I would have used lines as follows :

DIM TABLE(100,40)
FOR I = 1 TO 100 : FOR J= 1 TO 4
READ TABLE(I,J)
NEXT J: NEXT I

I know that macros can handle FOR/NEXT loops but what about getting the data
from a range say A1:D100

Thanks again in advance

Under Pressure



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading data into a 2 dimensional array


DIM TABLE(100,40)
FOR I = 1 TO 100
FOR J= 1 TO 4

READ TABLE(I,J) = cells(I,J)

NEXT J
NEXT I


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=168841

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default Reading data into a 2 dimensional array

On Mon, 11 Jan 2010 09:43:01 -0800, Under Pressure
wrote:

My original post on this appears to have disappeared, so here goes again.

I want to do some complex analysis on some data in a spreadsheet. I would
like to use a macro but don't know how to 'read' the data from the
spreadsheet into a 2 dimensional array. Back in the old days of programming
in GWBASIC, I would have used lines as follows :

DIM TABLE(100,40)
FOR I = 1 TO 100 : FOR J= 1 TO 4
READ TABLE(I,J)
NEXT J: NEXT I

I know that macros can handle FOR/NEXT loops but what about getting the data
from a range say A1:D100

Thanks again in advance

Under Pressure



Here is an example that you can modify according to your needs:

Function complex_analysis(r As Range)
Dim a() As Double
ReDim a(1 To r.Rows.Count, 1 To r.Columns.Count)
s = 0
' transfer the data from Range r to Array a
For i = 1 To r.Rows.Count
For j = 1 To r.Columns.Count
a(i, j) = r(i, j)
Next j
Next i

' do complex analyis, summing is just an example
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
s = s + a(i, j)
Next j
Next i

complex_analysis = s

End Function

Sub test()
MsgBox complex_analysis(Range("A1:D100"))
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Reading data into a 2 dimensional array

If you are reading values in from a worksheet, you don't need a loop at all.
This code will load up the Table array as you have indicated...

Dim TABLE() As Variant
TABLE = Range("A1:D20").Value

Just change my example range of A1:D100 to whatever range of cells you want
to put into your array variable.

--
Rick (MVP - Excel)


"Under Pressure" wrote in message
...
My original post on this appears to have disappeared, so here goes again.

I want to do some complex analysis on some data in a spreadsheet. I would
like to use a macro but don't know how to 'read' the data from the
spreadsheet into a 2 dimensional array. Back in the old days of
programming
in GWBASIC, I would have used lines as follows :

DIM TABLE(100,40)
FOR I = 1 TO 100 : FOR J= 1 TO 4
READ TABLE(I,J)
NEXT J: NEXT I

I know that macros can handle FOR/NEXT loops but what about getting the
data
from a range say A1:D100

Thanks again in advance

Under Pressure




Reply
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
Export 1-dimensional array values to a two-dimensional table? Laurie Excel Programming 2 November 8th 07 03:51 PM
Changing a two-dimensional, one row array to one-dimensional Alan Beban[_2_] Excel Programming 1 September 16th 07 08:56 PM
How to generate formula from two dimensional array of data KROATA Excel Worksheet Functions 1 December 2nd 05 12:39 PM
Create One-Dimensional Array from Two-Dimensional Array Stratuser Excel Programming 1 February 23rd 05 08:46 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 11:49 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"