Deleting Rows if Row (But 1st Cell) sums to 1

AndreSoares

New Member
Joined
May 13, 2014
Messages
14
Hey,

I have a worksheet (13200 rows x 24 columns) and need to clean up the rows in which all cells but the first one are equal to 1.

Any help is more than welcome, thank you so much in advance!

Best regards :)
André​
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
try now this will not delete header (Assuming it is in row 1)

Code:
Sub deleteRows()

Cells(2, 25).FormulaR1C1 = "=COUNTIF(RC[-23]:RC[-1],1)"
Cells(2, 25).AutoFill Destination:=Range("Y2:Y13200")

With Range(Cells(2, 25), Cells(13200, 25))
    .Copy
    .PasteSpecial Paste:=xlPasteValues
End With

Range(Cells(2, 1), Cells(13200, 25)).AutoFilter Field:=25, Criteria1:=">1"
Range(Cells(2, 1), Cells(13200, 25)).SpecialCells(xlCellTypeVisible).EntireRow.Delete

Columns(25).Delete

End Sub
 
Last edited:
Upvote 0
yeah:/

I was trying to edit the post but to late

Code:
Sub deleteRows()

Cells(1, 25).FormulaR1C1 = "=COUNTIF(RC[-23]:RC[-1],1)"
Cells(1, 25).AutoFill Destination:=Range("Y1:Y13200")

With Range(Cells(2, 25), Cells(13200, 25))
    .Copy
    .PasteSpecial Paste:=xlPasteValues
End With

Range(Cells(1, 1), Cells(13200, 25)).AutoFilter Field:=25, Criteria1:=">=1"
On Error Resume Next
Range(Cells(2, 1), Cells(13200, 25)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0

Columns(25).Delete

End Sub
 
Upvote 0
Ok, I see some results, but some rows still sum 1...
Even though it didn't totally work, I got from 13k to 3k rows! Can you trim this macro any better?
Thanks so much!
 
Upvote 0
it should remove all rows where "1" exists in columns between 2 and 24. I used count function not sum. can you give a sample data where the rows was not removed
 
Upvote 0
Hey again,
Here is a sample:
450000000000000000000000010

<tbody>
</tbody>

Also, I noticed the Y column disappeared after using the macro... :/
 
Upvote 0
Yes Column Y is 25th column (as per #1 macro need to check columns 2-24). The macro add formula there and then delete this column. If you need to check column B-AA it is 2-27. this is a reason why some rows are not deleted as Macro check 2-24 (B-X)

Check this code. It will check columns B to AA

Code:
Sub deleteRows()

Cells(1, 100).FormulaR1C1 = "=COUNTIF(RC[-98]:RC[-1],1)"
Cells(1, 100).AutoFill Destination:=Range(Cells(1, 100), Cells(13200, 100))

With Range(Cells(2, 100), Cells(13200, 100))
    .Copy
    .PasteSpecial Paste:=xlPasteValues
End With

Range(Cells(1, 1), Cells(13200, 100)).AutoFilter Field:=100, Criteria1:=">=1"
On Error Resume Next
Range(Cells(2, 1), Cells(13200, 100)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0

Range(Cells(1, 1), Cells(13200, 100)).AutoFilter
Columns(100).Delete

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,165
Messages
6,129,235
Members
449,496
Latest member
Patupaiarehe

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