Easy loop

G

Guest

I want to hide the entire row, if the value in column b is Yes.
So, I tried this:

Private Sub CAT()
For b = 1 To 25
If Cells(1, b) = "Yes" Then
Selection.EntireRow.Hidden = True
End If
Next b
End Sub

If cell B1 is Yes, it hides that row, but not any other rows with Yes in
column B. I don't know how to correct it.

Thanks,
 
G

Guest

that is because you are looping over columns, not rows:

Private Sub CAT()
For b = 1 To 25
If Cells( b,"B") = "Yes" Then
Selection.EntireRow.Hidden = True
End If
Next b
End Sub

or

Private Sub CAT()
For b = 1 To 25
If Cells( b, 2) = "Yes" Then
Selection.EntireRow.Hidden = True
End If
Next b
End Sub
 
G

Guest

Thank you very much!
--
Howard


Tom Ogilvy said:
that is because you are looping over columns, not rows:

Private Sub CAT()
For b = 1 To 25
If Cells( b,"B") = "Yes" Then
Selection.EntireRow.Hidden = True
End If
Next b
End Sub

or

Private Sub CAT()
For b = 1 To 25
If Cells( b, 2) = "Yes" Then
Selection.EntireRow.Hidden = True
End If
Next b
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

Top