ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding rows to a 2 dimensional array ... (https://www.excelbanter.com/excel-programming/376749-adding-rows-2-dimensional-array.html)

netnews.comcast.net[_3_]

Adding rows to a 2 dimensional array ...
 
Is it possible to add rows to a two dimensional array? I have a situation
where the number of rows can be different each time the array is used. I
need to preserve the existing data in the array when adding the additional
rows. I am using Excel 2003. Any help will be very much appreciated.

Thanks in advance,
Ralph Fraley



ahmadifx

Adding rows to a 2 dimensional array ...
 
Hi,
Try using the statement ReDim Preserve .. It might solve.. Im not sure bcos
it works in VB dono about VBA
--
Regards
Ahmad
Microsoft Student Partner - India


"netnews.comcast.net" wrote:

Is it possible to add rows to a two dimensional array? I have a situation
where the number of rows can be different each time the array is used. I
need to preserve the existing data in the array when adding the additional
rows. I am using Excel 2003. Any help will be very much appreciated.

Thanks in advance,
Ralph Fraley




Kai Uwe Schmidt

Adding rows to a 2 dimensional array ...
 
Hi Ralph,

you can use a dynamic two-dimensional aray, which means to create an array
with a not-fixed number of items.
You have to attach the row index to the array´s last dimension, since you
only can dynamically extend the last dimension. After the row size has has
increased, use "Redim Preserve". Perhaps the following might help you.

Best Regards,
Kai

Option Base 1
Dim arMatrix () as String
Dim objWb as workbook
Dim objWs as worksheet
Dim rngMatrix as range
Dim i as integer, j as integer

Set objWb = ActiveWorkbook
Set objWs = objWb.Worksheets(1)
Set rngMatrix = objWs.usedrange
...
For i= 1 to objMatrix.rows.count
For j = 1 to objMatrix.columns.count
arMatrix(j,i) = ws.cells(i,j) 'The dimension whose number
of items is changed must be put at last position.
Next j
Next i
...
'Number of rows has increased by 1.
'Extend the array´s last dimension.

Redim Preserve arMatrix(Ubound(arMatrix(),1),UBound(arMatrix(),2 +1)

'Extend the Source Matrix.
Set rngMatrix = objWs.usedrange

'Add the new line.
With rngMatrix
For j =1 to .columns.count
arMatrix(j,UBound(arMatrix(),2) = .cells(.rows.count,j)
End With
...
End Sub






RB Smissaert

Adding rows to a 2 dimensional array ...
 
Download Alan Beban's array functions from this website:
http://home.pacbell.net/beban/
One of the functions is ArrayAdd and I think will do exactly what you want.

RBS

"netnews.comcast.net" wrote in message
...
Is it possible to add rows to a two dimensional array? I have a situation
where the number of rows can be different each time the array is used. I
need to preserve the existing data in the array when adding the additional
rows. I am using Excel 2003. Any help will be very much appreciated.

Thanks in advance,
Ralph Fraley



Alan Beban

Adding rows to a 2 dimensional array ...
 
RB Smissaert wrote:
Download Alan Beban's array functions from this website:
http://home.pacbell.net/beban/
One of the functions is ArrayAdd and I think will do exactly what you want.

RBS

Hi RB,
The function is ResizeArray.

Alan Beban
"netnews.comcast.net" wrote in message
...
Is it possible to add rows to a two dimensional array? I have a
situation where the number of rows can be different each time the
array is used. I need to preserve the existing data in the array when
adding the additional rows. I am using Excel 2003. Any help will be
very much appreciated.

Thanks in advance,
Ralph Fraley



netnews.comcast.net[_3_]

Adding rows to a 2 dimensional array ...
 
Thanks to all; both solutions give me options and can work for me.

-Ralph Fraley

"netnews.comcast.net" wrote in message
...
Is it possible to add rows to a two dimensional array? I have a situation
where the number of rows can be different each time the array is used. I
need to preserve the existing data in the array when adding the additional
rows. I am using Excel 2003. Any help will be very much appreciated.

Thanks in advance,
Ralph Fraley





All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com