If Statement and Hiding rows with a Macro

IronHand

New member
Local time
Today, 06:05
Joined
Dec 8, 2004
Messages
7
Good Day,

I am hoping someone can help me with this IF Statement.

I have a spread sheet that I want to write a macro that says if any "T"s are in the B column, Hide the rows. For example, I would want to hide Aaron and AJ. But I don't know how to do this in Excel.

A B
Name Active/Terminated
David A
Justin A
Aaron T
Adem A
AJ T

Any help would be great. I have attached a bigger example with excel.

Thanks,
Jenn
 
Howdy. Try something like this. Adjust as appropriate.

Code:
Sub HideRows()
    Dim MyRange As Range, cl As Range
     
    Set MyRange = Sheet1.Range("B2:B65356")
Application.ScreenUpdating = False
    For Each cl In MyRange
        If cl.Value = "T" Then cl.EntireRow.Hidden = True
    Next cl
Application.ScreenUpdating = True
End Sub
________
Suzuki boulevard s50 history
 
Last edited:
Thanks, That worked perfectly.

Jenn
 
Here is a more efficient version:

Code:
Sub HideRows()
    Dim LastRow As Long, i As Long
     
    LastRow = Cells(65356, 2).End(xlUp).Row
Application.ScreenUpdating = False
    For i = LastRow To 2 Step -1
        If Cells(i, 2).Value = "T" Then Cells(i, 2).EntireRow.Hidden = True
    Next i
Application.ScreenUpdating = True
End Sub
________
BUY VAPORGENIE
 
Last edited:
Well after a long time, is there anyway
1. I can enable this hide statement to work in all my worksheets in one go?
2. How do I enable my Macros specifically for this VBA code - selective certificate?

thanks,
 

Users who are viewing this thread

Back
Top Bottom