#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Easy loop

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,
--
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Easy loop

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

--
Regards,
Tom Ogilvy



"Howard" wrote:

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,
--
Howard

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Easy loop

Thank you very much!
--
Howard


"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy



"Howard" wrote:

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,
--
Howard

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pretty easy If loop - help!! nemadrias Excel Worksheet Functions 9 July 7th 06 12:13 AM
How easy is it to loop in VBA based on cell contents? Lee Harris Excel Worksheet Functions 3 November 25th 05 01:21 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
new user with easy question? not easy for me speakeztruth New Users to Excel 5 June 3rd 05 09:40 PM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"