Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default append multiple worksheets data into a single multi-dimensional array

hi,

i have workbook which has columnar data in it which spans multiple sheets. i.e. each row is a single record which spans multiple worksheets. the rows are of fixed numbers across the sheets (say 200), but the columns vary to 255 or less. what i am trying to do is append the data in each sheet into a single multi-dimensional array (2-dimensions).

now the challenge is, i don't want to loop thru all the rows and columns in a sheet and go on appending at the end of the array.

has someone done something like this before using VBA? if so, can someone help? what will be a fast method?


Option Explicit

Sub ParseSheetsIntoSingleArray(UserWBK)
Dim wb As Workbook
Dim wk As Worksheet
Dim vfile() As Variant
Dim rng As Range
Dim counter As Integer
Dim numrows As Long, numcols As Long


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wb = Application.Workbooks.Open(UserWBK)

counter = 1

If Not wb Is Nothing Then
numrows = wb.Sheets(1).Cells(1, 1).End(xlDown).Row
ReDim vfile(1 To numrows, 1 To 1)

For Each wk In wb.Sheets
numrows = wk.Cells(1, 1).End(xlDown).Row
numcols = wk.Cells(1, wk.Columns.Count).End(xlToLeft).Column

ReDim Preserve vfile(1 To numrows, 1 To UBound(vfile, 2) + numcols)

If counter = 1 Then
Set rng = wk.Cells(1, 1).CurrentRegion
Else
'exclude 1st 2 columns in subsequent sheets
Set rng = wk.Range(wk.Cells(1, 3), wk.Cells(numrows, numcols))
End If

'i am assigning it this way, but in next iteration previous values dissapear
vfile = rng
counter = counter + 1

Next wk

wb.Close False
End If

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default append multiple worksheets data into a single multi-dimensional array

'i am assigning it this way, but in next iteration
'previous values dissappear
vfile = rng


Yes, because you are replacing, not appending.

I don't know how to append chunks (versus element by element) but guess that it would not reduce run-time anyway.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default append multiple worksheets data into a single multi-dimensional array

On Friday, April 6, 2012 5:52:18 PM UTC+5:30, merjet wrote:
'i am assigning it this way, but in next iteration
'previous values dissappear
vfile = rng


Yes, because you are replacing, not appending.

I don't know how to append chunks (versus element by element) but guess that it would not reduce run-time anyway.


so i guess there isn't much in VBA to appending chunks of data to an array without the process of looping.....consider the case when the data flows thousands of rows down & many columns across. it would really be a slow process to append such data to an array using a loop. :(
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default append multiple worksheets data into a single multi-dimensional array

Instead of appending your data to an array
why don't you dump your data on a temp sheet
and use filter or find method ?

I use below subroutine, for instance, to merge 20k+ rows.
It takes me no more than a sec really.

Sub trf(Sheet1 As String, Sheet2 As String)
Dim rng As Range
Dim lr As Double
With Worksheets(Sheet1)
Set rng = .Range("a2", .Range("a" & Rows.Count).End(xlUp))
End With
rng.EntireRow.Cut
lr = Worksheets(Sheet2).Range("A" & Rows.Count).End(xlUp).Offset(1,
0).Row
With Worksheets(Sheet2).Cells(lr, 1)
..Insert Shift:=xlDown
End With
End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default append multiple worksheets data into a single multi-dimensional array

On Friday, April 6, 2012 11:57:21 PM UTC+5:30, wrote:
Instead of appending your data to an array
why don't you dump your data on a temp sheet
and use filter or find method ?

I use below subroutine, for instance, to merge 20k+ rows.
It takes me no more than a sec really.

Sub trf(Sheet1 As String, Sheet2 As String)
Dim rng As Range
Dim lr As Double
With Worksheets(Sheet1)
Set rng = .Range("a2", .Range("a" & Rows.Count).End(xlUp))
End With
rng.EntireRow.Cut
lr = Worksheets(Sheet2).Range("A" & Rows.Count).End(xlUp).Offset(1,
0).Row
With Worksheets(Sheet2).Cells(lr, 1)
.Insert Shift:=xlDown
End With
End Sub


Hi,

the reason why i cannot dump into a sheet is because for a single record (row), the fields (columns) are spread across multiple sheets. 2ndly, working with worksheet would be slow if the records range into 1000 of rows.
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
Multi-Dimensional Array noname Excel Programming 16 October 20th 11 04:47 AM
Multi Dimensional Array steve Excel Programming 4 September 26th 06 07:33 PM
Multi Dimensional Array andym Excel Programming 11 July 10th 06 05:09 AM
Multi-Dimensional Array Let & Get Trip[_3_] Excel Programming 0 September 21st 05 08:41 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 05:20 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"