VBA to hide rows based on multiple criteria

klangston

New Member
Joined
May 23, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I can't download your add-in due to work IT restrictions, sorry.
I'm trying to hide rows too and I know I'm doing something wrong. If the values in $i3, $J3, $O3, or $Q3 =0 then hide row, if not then don't hide row. then go to the next row in file.
I have this:


Sub HideRows()
StartRow = 15
EndRow = 200
For i = StartRow To EndRow
If Cells(i, "I3:J3, O3:Q3").Value = "0.0" Then
Cells(i, "I3:J3, O3:Q3").EntireRow.Hidden = True
Else
Cells(i, "I3:J3, O3:Q3").EntireRow.Hidden = False
End If
Next i
End Sub

I appreciate your help
thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
First of all, you're making a comparison to text when you write "0.0"

Do you want to hide the row if ALL of those cells are =0 or ANY of them are = 0?
What if those cells are empty?
 
Upvote 0
First of all, you're making a comparison to text when you write "0.0"

Do you want to hide the row if ALL of those cells are =0 or ANY of them are = 0?
What if those cells are empty?
If the all of them =0
thanks
:-)
 
Upvote 0
Does this do what you want?

Code:
Sub HideRows()
Dim StartRow As Long, EndRow As Long, lr As Long, i As Long
StartRow = 15
EndRow = 200
For i = StartRow To EndRow
If (2 = WorksheetFunction.CountIf(Range("I" & i & ":J" & i), 0)) And (3 = WorksheetFunction.CountIf(Range("O" & i & ":Q" & i), 0)) Then
Rows(i).EntireRow.Hidden = True
Else
End If
Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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