semidevilz
New Member
- Joined
- Dec 11, 2015
- Messages
- 12
I found a vba script that works in deleting row based on cell value, but I would like help with
1. understanding it
2. make it run faster
I have a spreadsheet that has Dates in Column C. Every week, before I run my report, I delete all my data from the most recent 90 days. Cell "J2" is the "cut off date" that is automatically calculated. So if J2 = 01/01/2016, the code will delete all rows with dates > 01/01/2016
Sub DeleteRow()
Application.ScreenUpdating = False
Dim LR As Long
For LR = Range("C" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("C" & LR).Value > Range("J2").Value Then
Rows(LR).EntireRow.Delete
End If
Next LR
Question 1:
I still dont get what Range("C" & Row.count) means. Is it just counting the rows from column C?
What is Row To 2 Step -1?
Question 2:
The code seems to work fine, but my worksheet has almost 1 million rows and when I run it, it just keeps clocking. is there a way to run faster? I haven't had a successful execution yet.
will appreicate any feedback on the question or changes to the code.
1. understanding it
2. make it run faster
I have a spreadsheet that has Dates in Column C. Every week, before I run my report, I delete all my data from the most recent 90 days. Cell "J2" is the "cut off date" that is automatically calculated. So if J2 = 01/01/2016, the code will delete all rows with dates > 01/01/2016
Sub DeleteRow()
Application.ScreenUpdating = False
Dim LR As Long
For LR = Range("C" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("C" & LR).Value > Range("J2").Value Then
Rows(LR).EntireRow.Delete
End If
Next LR
Question 1:
I still dont get what Range("C" & Row.count) means. Is it just counting the rows from column C?
What is Row To 2 Step -1?
Question 2:
The code seems to work fine, but my worksheet has almost 1 million rows and when I run it, it just keeps clocking. is there a way to run faster? I haven't had a successful execution yet.
will appreicate any feedback on the question or changes to the code.