Thread: VBA arrays
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default VBA arrays

hokiebird wrote ...

I'm trying to access only part of an array.

Suppose A in an array of integers with 10 cells...
Dim A(1 to 10) as integer

..some code to fill up A

Now lets say I want to call a subroutine with only cells 4-8, how do I
do this?


Perhaps you'd prefer to use an in-memory object with more
functionality than an array e.g.

Sub Test()
Dim A As Object
Set A = CreateObject("ADODB.Recordset")
With A
.CursorLocation = 3
.Fields.Append "DataCol", 3
.Open

' code to fill up A
Dim i As Long
For i = 1 To 10
.AddNew "DataCol", i
Next

.Filter = "DataCol = 4 AND DataCol <= 8"
MsgBox .GetString
End With
End Sub

If you require an array as output, use the GetRows method (use
Excel.Application.Transpose to correspond with Excel's row,column
format). Rather than use hard-coded values, use a SQL query to fetch
the data.

Jamie.

--