Macro Tweek: Delete Blanks Used Range Only

shane_aldrich

Board Regular
Joined
Oct 23, 2009
Messages
148
Hi All,

Needing some help...I currently work with a raw data file with approx 300K rows... For a while, in column AY there were some blanks within the used range, so I used the macro below to delete rows with the blanks.

Here's the problem, now there are no blanks in the used range so when the filter is applied, it actually deletes every row even those with data. Of course from there I get run-time errors...

Here's the question, is there a way to search for/count blanks within the used cells, possibly based on a count for the number of used rows in column A or something?





'Remove Blanks
With ActiveSheet
'Count "" errors on AY:AY
If Application.WorksheetFunction.CountIf(.Range("AY:AY"), "") > 0 Then
'N/A found: Filter the range:
Rows("1:1").Select
Selection.AutoFilter
.Range("$A:$BE").AutoFilter Field:=51, Criteria1:="="
'Delete the rows displayed:
Application.DisplayAlerts = False
.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
Application.DisplayAlerts = True
'Close Autofilter
.Range("$A:$BE").AutoFilter
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
This will test if column AY has blanks within the used range
Code:
'Count "" errors on AY:AY
If Application.WorksheetFunction.CountIf(.Range("AY:AY"), "") > 0 And _
   [COLOR="Red"]Application.CountBlank(Intersect(Range("AY:AY"), .UsedRange)) > 0[/COLOR] Then
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,702
Members
452,938
Latest member
babeneker

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