Hide rows if the sum of values in rows is zero

nabeelzz

Board Regular
Joined
Sep 23, 2014
Messages
69
Sub HideRows()

Dim R As Long
Dim Rng As Range

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange
End If

For R = 1 To Rng.Rows.Count
If Application.Sum(Range(Rng(R, 3), Rng(R, Rng.Columns.Count))) = 0# Then
Rng.Rows(R).Hidden = True
End If
Next R

End Sub
Hi,
I am looking for VBA codes to hide rows for which sum is zero. I googled it and found the following codes.
"Sub HideRows()Dim R As Long
Dim Rng As Range
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange
End If
For R = 1 To Rng.Rows.Count
If Application.Sum(Range(Rng(R, 3), Rng(R, Rng.Columns.Count))) = 0# Then
Rng.Rows(R).Hidden = True
End If
Next R
End Sub"

The above code also hides blank rows. I dont want that. Someone responded to do the following;

"replace the FOR loop in each method with this....

myRange = Range(Rng(R, 3), Rng(R, Rng.Columns.Count))
For R = 1 To Rng.Rows.Count
If Application.CountBlank(myRange) <> myRange.Cells.Count Then
If Application.Sum(myRange) = 0# Then
Rng.Rows(R).Hidden = True
End If
Next R"

I dont know how to do this. I am a dummy when it comes to programming.

This hides blank rows as well. I am working on huge data where i want to the blank rows to be shown. Could some one help.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Sub HideRows()

Dim R As Long
Dim Rng As Range
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange
End If
For R = 1 To Rng.Rows.Count
If Application.Sum(Range(Rng(R, 3), Rng(R, Rng.Columns.Count))) = 0 And Application.WorksheetFunction.CountA(Rows(R)) > 0 Then
Rng.Rows(R).Hidden = True
End If
Next R
End Sub

This should do it for you.
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,104
Members
448,548
Latest member
harryls

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