Based on GSerg's suggestion, I did the following test to measure performance as well as changes in memory address.
// Shift column indices, without increasing number of columns
1000R x 20C --> 1000R x 20C = 4.7 micro secs (address remains same)
100,000R x 20C --> 100,000R x 20C = 6.3 micro secs (address remains same)
// Shift column indices, and increase number of columns
1000R x 20C --> 1000R x 21C = 80 micro secs (address changes)
100,000R x 20C --> 100,000R x 21C = 13.5 milli secs (address changes)
Following is the code, in case anyone interested
Option Explicit
Declare Function GetFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (Frequency As Currency) As Long
Declare Function GetTickCount Lib "kernel32" Alias "QueryPerformanceCounter" (TickCount As Currency) As Long
Sub Test()
Dim MyWorkSheet As Worksheet
Dim MyBuffer As Variant
Dim FirstRow As Long
Dim FirstCol As Long
Dim LastRow As Long
Dim LastCol As Long
Dim Message As String
Set MyWorkSheet = Sheets("Test")
FirstRow = 1
FirstCol = 1
LastRow = 100000
LastCol = 20
' Read the range into buffer
With MyWorkSheet
MyBuffer = .Range(.Cells(FirstRow, FirstCol), .Cells(LastRow, LastCol)).Value
End With
' Check the address before ReDim
Message = "Value At " & VarPtr(MyBuffer(FirstRow, FirstCol)) & " = " & MyBuffer(FirstRow, FirstCol)
' Shift the column indices
FirstCol = FirstCol + 100
LastCol = LastCol + 100 ' Modify this to change column count as well
' ReDim the buffer to shifted column indices and measure time taken
Timer
ReDim Preserve MyBuffer(FirstRow To LastRow, FirstCol To LastCol)
Timer
' Check the address after ReDim
Message = Message & Chr(10) & "Value At " & VarPtr(MyBuffer(FirstRow, FirstCol)) & " = " & MyBuffer(FirstRow, FirstCol)
MsgBox Message
End Sub
Sub Timer()
Dim TickCount As Currency
GetTickCount TickCount
Static Frequency As Currency
If Frequency = 0 Then
GetFrequency Frequency
End If
Static FirstTime As Double
If Frequency Then
If FirstTime <> 0 Then
MsgBox "Elapsed : " & (TickCount / Frequency) - FirstTime
FirstTime = 0
Else
FirstTime = TickCount / Frequency
End If
End If
End Sub