Dr. Demento
Well-known Member
- Joined
- Nov 2, 2010
- Messages
- 618
- Office Version
- 2019
- 2016
- Platform
- Windows
I have successfully adapated Michael M's code (found here, Post #4) to meet my needs (thanks much, Michael!). However, rather than add the pasted data to the end of the data, I wish to overwrite the previously pasted data (paste data at A5 everytime the macro is run). I suspect it has to do with the statement ".End(xlUp).Row" in multiple locations - I'm enough of a noob that I can't figure out how to adapt the code to overwrite existing data.
Any help would be much appreciated!
Dr. D
Michael M's original code:
Sub As_Of_Analysis_Sorting()
Dim lr As Long, lr2 As Long, r As Long
lr = Sheets("All Trades").Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Sheets("As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
lr3 = Sheets("Non-As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 2 Step -1
If Range("P" & r).Value = "YES" Then
Rows(r).Copy Destination:=Sheets("As-Of Trades").Range("A" & lr2 + 1)
lr2 = Sheets("As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
End If
If Range("P" & r).Value = "NO" Then
Rows(r).Copy Destination:=Sheets("Non-As-Of Trades").Range("A" & lr3 + 1)
lr3 = Sheets("Non-As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
End If
Range("A1").Select
Next r
End Sub
Any help would be much appreciated!
Dr. D
Michael M's original code:
Sub As_Of_Analysis_Sorting()
Dim lr As Long, lr2 As Long, r As Long
lr = Sheets("All Trades").Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Sheets("As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
lr3 = Sheets("Non-As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 2 Step -1
If Range("P" & r).Value = "YES" Then
Rows(r).Copy Destination:=Sheets("As-Of Trades").Range("A" & lr2 + 1)
lr2 = Sheets("As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
End If
If Range("P" & r).Value = "NO" Then
Rows(r).Copy Destination:=Sheets("Non-As-Of Trades").Range("A" & lr3 + 1)
lr3 = Sheets("Non-As-Of Trades").Cells(Rows.Count, "A").End(xlUp).Row
End If
Range("A1").Select
Next r
End Sub