View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
R Avery R Avery is offline
external usenet poster
 
Posts: 220
Default Remove First Row from Variant Array FAST?

This is an interesting idea, although you're right - it would not work
for an array with millions of rows because of the sheet row limitation.
Also, the writing and reading from ranges might make it slow.

Peter T wrote:
Also, a related question. Suppose I have a Double array
with millions of items in the array. Is there a quick
way to chop it in half,



Looks like you're having a hard time getting your question
across.

Maybe you can find something half useful in following. In
a new workbook step through the code.

Sub SampleData()
With Worksheets(2)
.Name = "arrOrig"
.UsedRange.Clear
.[A1] = 1: .[B1].Formula = "=A1+0.2"
.Range("A1:B1").AutoFill .Range("A1:B20000")

'.[C1].Formula = "=A1+0.3": .[D1].Formula = "=A1+0.4"
'.Range("C1:D1").AutoFill .Range("C1:D20000")
End With
Worksheets(3).Name = "temp"
Worksheets(1).Name = "arrHalf"
End Sub

Sub SplitArray()
Dim wsHalf As Worksheet, wsTmp As Worksheet
Dim vArr, aCols As Long, aRows As Long
Dim R As Range

Set R = Worksheets("arrOrig").UsedRange
aCols = R.Columns.Count: aRows = R.Rows.Count
Set wsHalf = Worksheets("arrHalf")
Set wsTmp = Worksheets("temp")

wsHalf.UsedRange.Clear

'right half
ReDim vArr(1 To aRows, aCols) As Long
vArr = R.Value

wsTmp.Range("A1").Resize(UBound(vArr, 1), _
UBound(vArr, 2)).Value = vArr

ReDim vArr(1 To aRows, aCols / 2)

vArr = wsTmp.Range("A1").Offset(0, aCols / 2). _
Resize(UBound(vArr, 1), UBound(vArr, 2)).Value

wsTmp.UsedRange.Clear

wsHalf.Range("A1").Resize(UBound(vArr, 1), _
UBound(vArr, 2)).Value = vArr

wsHalf.Activate
Stop

'bottom half
wsHalf.UsedRange.Clear
ReDim vArr(1 To aRows, aCols)
vArr = R.Value

wsTmp.Range("A1").Resize(UBound(vArr, 1), _
UBound(vArr, 2)).Value = vArr

ReDim vArr(1 To aRows / 2, aCols)

vArr = wsTmp.Range("A1").Offset(aRows / 2, 0). _
Resize(aRows / 2, UBound(vArr, 2)).Value

wsTmp.UsedRange.Clear

wsHalf.Range("A1").Resize(UBound(vArr, 1), _
UBound(vArr, 2)).Value = vArr
End Sub

You will need some working space, might need to add a temp
sheet to some workbook.
Array size is limited to sheet dimensions. So not millions
of rows, I havn't tried with 10,000 x 100 items.
Array must be 2D, even if only one row or col of data.
Lbound must not be 0 (try Option base 1).

Should be able to re-dimension & re-populate your array
with any "rectangular area" within the original array.

Regards
Peter


-----Original Message-----
Suppose I have a 2D variant array, and I want to remove


the first row
from it. Is there a really fast way to do that, rather

manually copying

every value into a new variant array? Perhaps using API


calls or

manipulating the underlying SAFEARRAY structure?

Also, a related question. Suppose I have a Double array


with millions

of items in the array. Is there a quick way to chop it


in half, perhaps

by altering the pointer to the first index and altering


the number of

items in the SAFEARRAY?

I am not experienced with any of this stuff, but I


thought it might be

possible. It would useful to me, if possible. Any help


would be

appreciated.
.