• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to hide/unhide rows based on cell value

Nightlytic

Member
So... I see plenty of VBA codes online but I can't get any to work :/ I'm not very good at VBA.

I have a spreadsheet, I set it to have Col. AT say either "1" or "2", and I want a VBA that will look at col. AT, rows 1 through to 1315, and hide entire rows where AT=1, and unhide them where AT=2... This macro should stop at row 1315. I think I will attach it to a button...


I will show you one example of what I saw online:

Sub PG1()
If Range("E50").Value ="Passed"Then Rows("51:51").EntireRow.Hidden =TrueElse
If Range("E50").Value ="Failed"Then Rows("51:51").EntireRow.Hidden =FalseEnd
IfEndSub

I played around with it changing the columns and rows but it's tossing up errors.
 
Do You use number 1 & 2 or characters "1" & "2"?
How do You handle if there is empty cell?

Copy this sample and run it ...

Code:
Sub Chk_AT()
    Application.ScreenUpdating = False
    With ActiveSheet
        .Range("AT1:AT1315").Interior.ColorIndex = xlNone
        For y = 1 To 1315
            RH = -1
            Select Case .Cells(y, 46)
                Case 1, "1"
                    .Cells(y, 1).RowHeight = 0
                Case 2, "2"
                    .Cells(y, 1).RowHeight = 14
                Case Else
                    .Cells(y, 46).Interior.ColorIndex = 3
            End Select
        Next y
    End With
    Application.ScreenUpdating = True
End Sub
 
Back
Top