Macro to hide rows based on cell value

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
Like to create a macro (button) to hide / unhide rows based on a cell value
Example
A1=No then hide roa A
C1=No then hide row c
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
It would affect any row that has the value of "No" in a cell. It would then only show those rows where the reponse was "Yes"
 
Upvote 0
Try:

Code:
Sub HideNos()
  For i = 1 to Range("A65536").end(xlup).Row
    If UCase(Cells(1, i).value) = "NO" then Cells(1, i).entireRow.Hide
  Next i
End Sub

I wrote this then got confused because you say "A1=No then hide row A" but A is a column. Do you want to hide the columns? Or do you want to hide row 1, and if A3=No then hide row 3? My code goes through column A and hides all of the rows where the value of A equals to No.

Hope this helps!
 
Upvote 0
Changed the code to

Sub HideNos()
For i = 1 To Range("A500").End(xlUp).Row
If UCase(Cells(i, 5).Value) = "NO" Then Cells(i, 1).EntireRow.Hide
Next i
End Sub

But, it goes to debug and highlights the " Cells(i, 1).EntireRow.Hide " segment
 
Upvote 0
Just for your info, I found an alternate method that also works

Sub HideRows()
Dim cell As Range
For Each cell In Range("e:e")
If UCase(cell.Value) = "NO" Then
cell.EntireRow.Hidden = True
End If
Next
End Sub



Thanks for the help, great forum
 
Upvote 0
Five and a half years later, I dont know if the guys that started this thread are still around, but I have a supplimentary question.

Is it possible to adapt the code below so that if it is run more than once it analyses all previously hidden rows and reinstates them if all rows do not contain "No"?
 
Upvote 0

Forum statistics

Threads
1,214,419
Messages
6,119,389
Members
448,891
Latest member
tpierce

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