Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default 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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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



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
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
Create One-Dimensional Array from Two-Dimensional Array Stratuser Excel Programming 1 February 23rd 05 08:46 PM
Adding rows to an array chris w Excel Worksheet Functions 1 December 10th 04 02:27 AM
Beginners' Question : How to move selected columns & rows to a two dimensional array Erche DP Excel Programming 3 July 18th 03 03:25 PM
Beginners' Question : How to move selected columns & rows to a two dimensional array Erche Excel Programming 4 July 18th 03 04:19 AM


All times are GMT +1. The time now is 10:00 PM.

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

About Us

"It's about Microsoft Excel"