ianawwalker
New Member
- Joined
- Feb 16, 2023
- Messages
- 15
- Office Version
- 365
- 2021
- Platform
- Windows
Hello,
I have vba that updates rows if the record is there and then adds the row if the record isn't there. It works great if there are less than 100 items that the vba needs to review, because it needs to loop through each individual line to see if it needs to update it. Hoping someone can review my code below to see if there is a faster way i can have this vba process this, as currently it takes over 30 min for it to review around 5,000 records and there are times were i need it to review 15,000 to 25,000 records. Appreciate any help! thank you!
OfflineRecordCount = Sheets("Offline").Range("a2").End(xlDown).Row - 3
Application.ScreenUpdating = False
For i = 1 To OfflineRecordCount
Sheets("input_posting").Range("OfflineLoanNum") = Sheets("offline").Range("a3").Offset(i)
offlinerecord = Sheets("input_posting").Range("Offlinematch") - 3
If Sheets("input_posting").Range("offlinematch") > 0 Then
Sheets("offline").Range("a3").Offset(i).EntireRow.Copy
'paste
Sheets("records").Select
ActiveSheet.Range("StartSpot").Offset(offlinerecord).Select
ActiveSheet.Paste
Sheets("offline").Range("a3").Offset(i).EntireRow.ClearContents
Else
'copy
Sheets("offline").Range("a3").Offset(i).EntireRow.Copy
'paste
Sheets("Records").Select
ActiveSheet.Range("a3").Select
ActiveCell.End(xlDown).Offset(1).Select
ActiveSheet.Paste
Sheets("offline").Range("a3").Offset(i).EntireRow.ClearContents
End If
Next i
i = 0
MsgBox ("Import Complete")
'clear conents
Sheets("input_Screen").Select
Range("LoanNum").Select
Application.ScreenUpdating = True
I have vba that updates rows if the record is there and then adds the row if the record isn't there. It works great if there are less than 100 items that the vba needs to review, because it needs to loop through each individual line to see if it needs to update it. Hoping someone can review my code below to see if there is a faster way i can have this vba process this, as currently it takes over 30 min for it to review around 5,000 records and there are times were i need it to review 15,000 to 25,000 records. Appreciate any help! thank you!
OfflineRecordCount = Sheets("Offline").Range("a2").End(xlDown).Row - 3
Application.ScreenUpdating = False
For i = 1 To OfflineRecordCount
Sheets("input_posting").Range("OfflineLoanNum") = Sheets("offline").Range("a3").Offset(i)
offlinerecord = Sheets("input_posting").Range("Offlinematch") - 3
If Sheets("input_posting").Range("offlinematch") > 0 Then
Sheets("offline").Range("a3").Offset(i).EntireRow.Copy
'paste
Sheets("records").Select
ActiveSheet.Range("StartSpot").Offset(offlinerecord).Select
ActiveSheet.Paste
Sheets("offline").Range("a3").Offset(i).EntireRow.ClearContents
Else
'copy
Sheets("offline").Range("a3").Offset(i).EntireRow.Copy
'paste
Sheets("Records").Select
ActiveSheet.Range("a3").Select
ActiveCell.End(xlDown).Offset(1).Select
ActiveSheet.Paste
Sheets("offline").Range("a3").Offset(i).EntireRow.ClearContents
End If
Next i
i = 0
MsgBox ("Import Complete")
'clear conents
Sheets("input_Screen").Select
Range("LoanNum").Select
Application.ScreenUpdating = True