Delete entire row if cells are blank

LearnVBA83

Board Regular
Joined
Dec 1, 2016
Messages
109
Office Version
  1. 365
Platform
  1. Windows
Hi team,

Does anyone know how to fix the below code. basically I want to delete the entire row if columns A - G are blank.

Code:
Sub delete()




Columns("A:G").SpecialCells(xlCellTypeBlanks).EntireRow.delete


End Sub


CHK NBR CHK ACCT NBRCHK ABA #CHECK AMTINVOICE AMTINVOICE# CUST #BATCHSEQ#SYS SEQ #Lock BoxDeposit DateTie Out
1840446017480976520016333362.653362.65H448561389083168100111111000121303/12/20170
11211000121303/12/20170
292824356752221271935263.05263.05H445756480042333100111311000221303/12/20170
11411000221303/12/20170
12944310682508312013601387.41387.4H449628691487882100111511000321303/12/20170
11611000321303/12/20170
116383220020567122000496249.51249.51H446776582313267100111711000421303/12/20170
11811000421303/12/20170
1925501049548421107515016799.14121200000121303/12/201716799.14
22943301085303121140399340.6917139.83H4479700864775941002122200000121303/12/2017-16799.14
123200000121303/12/20170
81764349901293221272031853.4124200000221303/12/2017853.4
709869058202321000021134.8988.2H4450757113671801003125200000221303/12/2017-853.4
126200000221303/12/20170
346056378839291121042882321.1127200000321303/12/2017321.1
15998325059351553121000358189.8510.9H4450099106785121001128200000321303/12/2017-321.1
129200000321303/12/20170
2929964172660987121000248730.861210200000421303/12/2017730.86
10279241280452591210002481394714677.86H45190139529465910011211200000421303/12/2017-730.86
1212200000421303/12/20170
323858016694221172212793.431213200000521303/12/2017793.43
47011374346210000212155.421214200000521303/12/20172155.42
16484301358704111030932155.425104.27H45245479623266410011215200000521303/12/2017-2948.85
1216200000521303/12/20170

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Does this do what you want

Code:
Sub delblank()
Dim lr As Long
lr = Cells(Rows.Count, 8).End(xlUp).Row
For x = lr To 2 Step -1
    If Application.WorksheetFunction.CountBlank(Range("A" & x & ":G" & x)) Then
        Rows(x).EntireRow.Delete
    End If
Next x

End Sub
 
Upvote 0
Hi Scott T,

Thanks for the help. That code almost works. I need it delete the entire row only if columns A, B, C, D, E, F, G are all blank together. So if there is any information in any of those columns then I want the macro to skip it, but if all 7 columns are blank in a row then i want to delete the entire row. Thanks for the help!!!
 
Upvote 0
Try

Code:
Sub delblank()
Dim lr As Long
lr = Cells(Rows.Count, 8).End(xlUp).Row
For x = lr To 2 Step -1
    If Application.WorksheetFunction.CountBlank(Range("A" & x & ":G" & x)) = 7 Then
        Rows(x).EntireRow.Delete
    End If
Next x
End Sub
 
Upvote 0
Hi Scott T,

That seems to work fine, although I'm having trouble getting it to run on my whole data set. Do you think 500,000+ lines is too much?

Thanks - B
 
Upvote 0
With that many lines it will take some time to go though all the line but it should work.

Right new the code uses column H the 8th column) to find the last row. If need you should change this to a column that will always have data so you get the correct last row
Code:
lr = Cells(Rows.Count, [COLOR=#FF0000]8[/COLOR]).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,215,892
Messages
6,127,613
Members
449,390
Latest member
joan12

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