Deleting Records that match certain values

vladi305

Board Regular
Joined
Jan 12, 2023
Messages
88
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a worksheet that gets over 80,000 rows daily, must of it needs to be filtered and ends with around 100 to 300 rows only.
Sorting the unwanted values and deleting rows manually is a pain and it takes me from 2 to 3 hours so I started doing with VBA using a code I found on this forum which uses a loop but it's extremely slow

Any ideas of how you have approached similar work

Thanks in advance
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try to record macro with Advance Filter, apply conditions, delete visible rows then remove Advance Filter
 
Upvote 0
If you have one validation standard for delete, Let me show you my example,

Coding :

VBA Code:
' Start Point 
' Usually Row "A" is heading
' Column A should have a value and not allowed "no value" until the record end. 

Range("A2").select

Do while len(activecell.value)<>0
      if activecell.value = "XXXX" ' then
         ' Above Statement is equal to Your validation standard Statement, 
         ' for example, your Column A data is "Male" or "Female", you want to delete "Female", then your code "if activecell.value = "Female" ' then"
            Activecell.Entirerow.delete   ' Delete the row if your statement is True
            activecell.offset(-1,0).select  '          
      end if
      activecell.offset(1,0).select
Loop
 
Last edited by a moderator:
Upvote 0
The fastest way to delete a large volume of rows is the code that @Peter_SSs has posted here:
Possible to make this macro faster?
The code will sort on a new column that flags rows to be deleted with a "1" and then deletes them in a single block.
So inside the For loop put whatever conditions (if statements) that identify the rows to be deleted and make sure the following 2 lines are triggered by those conditions.
VBA Code:
         b(i, 1) = 1
          k = k + 1

Another option would be to use Power Query.
 
Upvote 0
This is what I have
With ActiveSheet
vCol = "G"
vValue = 106
FirstRow = 1
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

'Loop Through Rows (Bottom to Top)
For Row = LastRow To FirstRow Step -1
If .Range(vCol & Row).Value = vValue Then
.Range(vCol & Row).EntireRow.Delete
End If
End With

I'll explore all options above and see which one is a better
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,149
Members
452,382
Latest member
RonChand

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