Help deleting empty rows in all sheets

MZING81

Board Regular
Joined
Mar 20, 2012
Messages
74
Just a beginner with VBA, trying to get this code to work in all sheets. Right now in only works in the active sheet. Ultimately it's supposed to delete all empty rows in all the worksheets.




Code:
Public Sub DeleteCompletelyBlankRows() 

Dim as worksheet

For each WS in Worksheets 

Dim R As Long
Dim C As Range
Dim N As Long
Dim Rng As Range
On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
N = 0
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).EntireRow) = 0 Then
Rng.Rows(R).EntireRow.Delete
N = N + 1
End If
Next R
EndMacro:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Any Help is greatly appreciated
MZING81
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
[color=darkblue]Public[/color] [color=darkblue]Sub[/color] DeleteCompletelyBlankRows()

    [color=darkblue]Dim[/color] WS  [color=darkblue]As[/color] Worksheet
    [color=darkblue]Dim[/color] R   [color=darkblue]As[/color] [color=darkblue]Long[/color]

    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] EndMacro
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    Application.Calculation = xlCalculationManual
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] WS [color=darkblue]In[/color] Worksheets
        [color=darkblue]With[/color] WS.UsedRange
            [color=darkblue]For[/color] R = .Rows.Count [color=darkblue]To[/color] 1 [color=darkblue]Step[/color] -1
                [color=darkblue]If[/color] Application.WorksheetFunction.CountA(.Rows(R).EntireRow) = 0 [color=darkblue]Then[/color]
                    .Rows(R).EntireRow.Delete
                [color=darkblue]End[/color] [color=darkblue]If[/color]
            [color=darkblue]Next[/color] R
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]Next[/color] WS
    
EndMacro:
    Application.ScreenUpdating = [color=darkblue]True[/color]
    Application.Calculation = xlCalculationAutomatic
        
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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