Sub Test_3DArray()
'
Dim startTime As Single
'
startTime = Timer ' Start the Stop watch
'
Application.ScreenUpdating = False ' Turn ScreenUpdating Off
''
Dim ArrayColumnNumber As Long, ArrayColumnNumberStart As Long, ColumnNumberOffset As Long, LastColumnNumberInSheet As Long
Dim ArrayNumber As Long
Dim ArrayRow As Long, DestinationArrayRow As Long, LastRowInBlockRange As Long, LastRowInSheet As Long
Dim LastRowInBlockRangeFinder As Long, StartRowOfHeader As Long
Dim DataBlockSize As Long, NumberOfDataBlocks As Long
Dim DestinationArray As Variant, SourceArray As Variant
Dim wsDestination As Worksheet, wsSource As Worksheet
'
ArrayColumnNumberStart = 1 ' <--- Set this to the start column
DataBlockSize = 4 ' <--- Set this to the # of columns per block
StartRowOfHeader = 1 ' <--- Set this to the start row
Set wsDestination = Sheets("Sheet2") ' <--- Set this to the destination sheet
Set wsSource = Sheets("Sheet1") ' <--- Set this to the source sheet
'
LastColumnNumberInSheet = Sheets("Sheet1").Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column ' Returns last Column Number in sheet
LastRowInSheet = Sheets("Sheet1").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row ' Returns last Row Number in sheet
NumberOfDataBlocks = LastColumnNumberInSheet / DataBlockSize ' Returns # of Data sections
ColumnNumberOffset = 0 ' Initialize the ColumnNumberOffset
'
ReDim SourceArray(1 To NumberOfDataBlocks) ' Set the # of arrays to be used
'
For LastRowInBlockRangeFinder = 1 To NumberOfDataBlocks ' Loop through each data range to find last row
LastRowInBlockRange = wsSource.Range(wsSource.Cells(StartRowOfHeader, _
ArrayColumnNumberStart + ColumnNumberOffset), wsSource.Cells(LastRowInSheet, _
ColumnNumberOffset + DataBlockSize)).Find("*", , xlFormulas, , xlByRows, xlPrevious).Row ' Find last Row Number of each block of data
'
SourceArray(LastRowInBlockRangeFinder) = wsSource.Range(wsSource.Cells(StartRowOfHeader, _
ArrayColumnNumberStart + ColumnNumberOffset), wsSource.Cells(LastRowInBlockRange, _
ColumnNumberOffset + DataBlockSize)) ' Save each range of data into SourceArray
'
ColumnNumberOffset = ColumnNumberOffset + DataBlockSize ' Adjust the ColumnNumberOffset for next range
Next ' Loop back
'
' At this point, all of the data blocks have been loaded to the 3D 1 based SourceArray (Array#)(R,C)
'
DestinationArrayRow = 0 ' Initialize DestinationArrayRow
ReDim DestinationArray(1 To NumberOfDataBlocks * LastRowInSheet, 1 To DataBlockSize) ' Set the Row size & Column size of DestinationArray
'
For ArrayNumber = 1 To NumberOfDataBlocks ' Loop through each array
For ArrayRow = LBound(SourceArray(ArrayNumber)) To UBound(SourceArray(ArrayNumber)) ' Loop through each array row
DestinationArrayRow = DestinationArrayRow + 1 ' Increment DestinationArrayRow
'
For ArrayColumnNumber = 1 To DataBlockSize ' Loop through each array column
DestinationArray(DestinationArrayRow, ArrayColumnNumber) = _
SourceArray(ArrayNumber)(ArrayRow, ArrayColumnNumber) ' Save result to DestinationArray
Next ' Loop back
Next ' Loop back
Next ' Loop back
'
wsDestination.Range("A1").Resize(UBound(DestinationArray, 1), UBound(DestinationArray, 2)) = DestinationArray ' Display Final results to destination
'
Application.ScreenUpdating = False ' Turn ScreenUpdating back on
'
Debug.Print "Time to complete = " & Timer - startTime & " seconds." ' Display the time elapsed to the user (Ctrl-G)
End Sub