Deleting 52k records by value in column A

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,362
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a worksheet with which fills at almost 300k rows and out to column AA. I need to delete all the 2014 records which are about 53k. I've used a macro to filter by column A and used the notoriously slow looping, but both of these lockup and or after ten minutes I stopped the macro. I'm using a test sheet to see if I can get this working, but of course will have to do this on the real workbook when done. Here is what I tried. Any suggestions.

VBA Code:
Sub Del2014()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
TurnEverythingOff
On Error GoTo Skip
For i = LR To 1 Step -1
If Range("A" & i).Value = 2014 Then Rows(i).Delete
Next i
Skip:
TurnEverythingOn
End Sub

VBA Code:
Sub TurnEverythingOff()
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
End Sub

VBA Code:
Sub TurnEverythingOn()
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Are the 2014 record in consecutive cells, or spread throughout the column?
If the latter, are you happy to sort the data?
 
Upvote 0
Ok, how about
VBA Code:
Sub Frygirl()
   With ActiveSheet
      .Range("A1").AutoFilter 1, "2014"
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Either one of these should do what you want also if the values are consecutive.
Code:
Sub Maybe_A()
With Sheets("Sheet1").Columns(1)
    .Range(.Find(2014, , , 1, , 1), .Find(2014, , , 1, , 2)).EntireRow.Delete
End With
End Sub

Code:
Sub Maybe_B()
    ActiveSheet.Columns(1).Range(Columns(1).Find(2014, , , 1, , 1), Columns(1).Find(2014, , , 1, , 2)).EntireRow.Delete
End Sub
 
Upvote 0
You're welcome.
Hope you can use it somewhere sometime
Good Luck
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top