If or Case help - Which to use

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

I'm trying to say from rows 31 thru 1000, if U and V are zero then hide the
row. if not both zero then show the row.

Having problems putting this into an if statment wondering if I'd be better
served using a case statement but not sure how to write it.
 
Something like this...

Dim rng As Range
Dim rngToSearch As Range

With Application
..Calculation = xlCalculationManual
..ScreenUpdating = False
End With
Set rngToSearch = Range("U31:U1000")
rngToSearch.EntireRow.Hidden = False

For Each rng In rngToSearch
If rng.Value = 0 And rng.Offset(0, 1).Value = 0 Then _
rng.EntireRow.Hidden = True
Next rng

With Application
..Calculation = xlCalculationAutomatic
..ScreenUpdating = True
End With
 
Stephen

Either should work; but, since you really only have two options (hide
or not hide), I would go with a simple if statement.

Something like:

Unhide all the rows,t hen run this.

Sub test()

For i = 31 To 1000
If Application.And(Cells(i, 21) = 0, Cells(i, 22) = 0) Then
Rows(i).Hidden = True
End If
Next i

End Sub

should work for you.

Good luck.

Ken
Norfolk, Va
 
The If is simple:

Sub stephen()
For i = 31 To 1000
If Cells(i, "U").Value = 0 And Cells(i, "V").Value = 0 Then
Cells(i, "U").EntireRow.Hidden = True
End If
Next
End Sub
 
if not both zero then show the row.

If you wish to show them also, perhaps:

Sub Demo()
Dim Rng As Range
For Each Rng In [U31:U1000].Cells
Rng.EntireRow.Hidden = Rng = 0 And Rng(1, 2) = 0
Next Rng
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top