PDA

View Full Version : Solved: Loop through a range and hide active Column



simora
06-20-2010, 05:01 PM
I'm trying to loop through a range and hide the column where the active cell is located if the column value is < 1 or "" or $0.00

This is the code that I have. It does not delete the columns even though the value is 0



Dim MyCell As Range, MyRange As Range

Set MyRange = Range("M204:U204")
For Each MyCell In MyRange
If MyCell.Value < 1 Or MyCell.Value = "" Then

ActiveCell.EntireColumn.Hidden = True
End If
Next MyCell



Can anyone tell me why this code is not hiding the column

Thanks

GTO
06-20-2010, 06:42 PM
Hi Simora,

Change ActiveCell to MyCell:


Sub exa()
Dim MyCell As Range, MyRange As Range

Set MyRange = Range("M204:U204")
For Each MyCell In MyRange

If MyCell.Value < 1 Or MyCell.Value = "" Then

MyCell.EntireColumn.Hidden = True
End If
Next MyCell
End Sub

ActiveCell is not changing, as the ActiveCell is just whatever cell is selected on the ActiveSheet.

BTW, you might want to be careful in titling your thread. Deleting columns is of course a bit different than hiding them for a bit.

Hope that helps,

Mark

simora
06-21-2010, 02:04 AM
Thanks Mark:

The Delete column bit was a Typo. My worksheet has gremlins living there now.

Thanks again.