Deleting rows based on multiple filter options

Nagartath

New Member
Joined
Sep 15, 2006
Messages
19
Hi, I need to review a 400,000 row spreadsheet and remove all records where 5 columns are populated with data so I am only eft with records that are missing information.

I haven't got the slightest clue how to go about this using VB.

Any and all help very much appreciated
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
Does Column A, or any other column have data in it 100% of the time?
 

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I am assuming that Column A has data 100% of the time, and the 5 Columns are B-F

Code:
Sub DeleteIt()
Dim LR As Long
Dim rng As Range
LR = Cells(Rows.Count, 1).End(xlUp).Offset(-1).Row
For Each rng In [A2].Resize(LR)
    If Application.CountBlank(rng.Offset(, 1).Resize(, 5)) = 0 Then
        rng.Clear
    End If
Next rng
On Error Resume Next
    Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub
 

Nagartath

New Member
Joined
Sep 15, 2006
Messages
19
Hi, the impacted columns are:
E
G
I
M
N

I don't know how to upload a file I'm afraid, any help on that would be helpful
 

Nagartath

New Member
Joined
Sep 15, 2006
Messages
19
Hi CSTIMART, when I run the code it deletes all rows in my database....any suggetions.....I have re-org'ed my spreadsheet to reflect B through to F are the columns I am interested in.

All help greatly appreciated
 

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
Does Column A contain data for each record 100% of the time?
 

Nagartath

New Member
Joined
Sep 15, 2006
Messages
19
Yes, column A is populated 100% of the time, it contains a unique reference number.
 

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I am assuming that the 5 cells that are "blank" aren't truly "blank", because the code should only delete rows where all 5 of those cells are blank.
 

Nagartath

New Member
Joined
Sep 15, 2006
Messages
19
I am assuming that the 5 cells that are "blank" aren't truly "blank", because the code should only delete rows where all 5 of those cells are blank.
Thanks cstimart, I was looking for code to delete the rows where the 5 cells are not blank, if all 5 cells in the row are populated (B thru to F) I want to delete the entire row, if just one of those cells is populated I want to keep the row.

Apologies if I wasn't clear in my original request.
 

Watch MrExcel Video

Forum statistics

Threads
1,095,229
Messages
5,443,220
Members
405,219
Latest member
CraneS

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top