Dimitris254
Board Regular
- Joined
- Apr 25, 2016
- Messages
- 139
I have a worksheet with 10 columns, two of which (J and K).
J column takes various text values, one of which is "External Research".
K column takes year values (they are formatted as "General" type), starting 2001.
I want to delete the whole row, when J is "External Research" or K is <=2015 (so keep only the current year 2016 and later).
i tried this, but the macro takes just too long (total rows ~50k) :
What is a better way to do this?
J column takes various text values, one of which is "External Research".
K column takes year values (they are formatted as "General" type), starting 2001.
I want to delete the whole row, when J is "External Research" or K is <=2015 (so keep only the current year 2016 and later).
i tried this, but the macro takes just too long (total rows ~50k) :
Code:
Option Explicit
Sub clear_years_inputtype()
Dim lastRow As Long
Dim i As Long
Dim wsRAWDATA As Worksheet
Application.ScreenUpdating = False
Set wsRAWDATA = ThisWorkbook.Worksheets("RAWDATA")
With wsRAWDATA
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow
If .Cells(i, "J") = "External Research" Or .Cells(i, "K") <= 2015 Then
.Rows(i).EntireRow.Delete
lastRow = lastRow - 1
i = i - 1
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
What is a better way to do this?