Problem counting blank cells

307Fergie

New Member
Joined
Jan 13, 2019
Messages
7
The code below is part of a larger macro which, subject to certain conditions, creates a blank cell in column A. This is used as a marker to enable the entire row to be deleted later. In testing I have found that very occasionally a file will come through which does not meet the conditions, and so no blank cell is created. At this point the code falls over with an error that the cells to be deleted cannot be found. In order to overcome this I wrote the posted code. I have used this successfully on numerous occasions, but always to count an actual value as opposed to a blank cell. I am still getting the same error message as the If statement doesn't appear to be working and I think this is because it's not counting the blank cells. I just can't work out what I am doing wrong. Any help would be appreciated.
Code:
Dim instances1 As Long
        instances1 = WorksheetFunction.CountIf(Range("A:A"), "")
            If instances1 > 0 Then _
                Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete              
           End If
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You can bypass/ignore those errors like this:
Code:
        [COLOR=#ff0000]On Error Resume Next[/COLOR]
        Dim instances1 As Long
        instances1 = WorksheetFunction.CountIf(Range("A:A"), "")
        If instances1 > 0 Then _
            Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete              
        End If
        [COLOR=#ff0000]On Error GoTo 0[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,207,442
Messages
6,078,581
Members
446,349
Latest member
Malroos7912

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