View Full Version : If Statement and Hiding rows with a Macro


IronHand
01-04-2006, 11:34 AM
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

shades
01-04-2006, 01:26 PM
Howdy. Try something like this. Adjust as appropriate.


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

IronHand
01-04-2006, 07:03 PM
Thanks, That worked perfectly.

Jenn

shades
01-05-2006, 09:31 AM
Here is a more efficient version:


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

Alexcali1
07-29-2008, 06:22 AM
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,