JeffGrant
Well-known Member
- Joined
- Apr 7, 2021
- Messages
- 558
- Office Version
- 365
- Platform
- Windows
Hi All,
I have started to learn about arrays and how they can speed up my model.
With the code below, I am looking to delete rows where the Date is older than "Date - 29". No drama.
The array is read in from shErrorIn (sheet2) and written out to shErrorOut (Sheet3). No drama.
What is happening is that on the first pass, the arrany is read in from shErrorIn but it is also written out to the same sheet.
Then running the code a second time, the array is written out to shErrorOut, where I want it.
I dont understand why the output array is being written back to the input sheet because I want to preserve the data on the input sheet.
Thanks for yoru guidance.
I have started to learn about arrays and how they can speed up my model.
With the code below, I am looking to delete rows where the Date is older than "Date - 29". No drama.
The array is read in from shErrorIn (sheet2) and written out to shErrorOut (Sheet3). No drama.
What is happening is that on the first pass, the arrany is read in from shErrorIn but it is also written out to the same sheet.
Then running the code a second time, the array is written out to shErrorOut, where I want it.
I dont understand why the output array is being written back to the input sheet because I want to preserve the data on the input sheet.
Thanks for yoru guidance.
VBA Code:
Sub ReadRangeError()
Dim rg As Range
Dim arr As Variant
Dim rowCount As Long, columnCount As Long, i As Long
Set rg = shErrorIn.Range("A1").CurrentRegion
arr = rg.Value
shErrorOut.Range("A1").CurrentRegion.ClearContents
rowCount = UBound(arr, 1)
columnCount = UBound(arr, 2)
For i = rowCount To 2 Step -1
If arr(i, 6) <= Date - 29 Then
Rows(i).EntireRow.Delete
End If
Next i
shErrorOut.Range("A1").Resize(rowCount, columnCount).Value = arr
End Sub