PDA

View Full Version : Solved: Hiding Columns if all cells = zero



Andybuck86
08-28-2010, 05:42 AM
Hi guys, I need some more help please!

I would like to be able to hide several columns in my spreadsheet if one specific cell in each column = zero

For example:

IF W35 = zero then hide the entire column W
IF X35 = zero then hide the entire column X

This will be the same for columns W:AI.

Is this possible?

Many thanks as always


Andy

mohanvijay
08-28-2010, 06:31 AM
Hai try this




Dim x As Integer
x = 22
For i = 1 To 13
chk_value = Cells(35, x + i)

If chk_value = 0 Then

Columns(x + i).EntireColumn.Hidden = True

End If
Next i

Bob Phillips
08-28-2010, 08:39 AM
Public Sub Test()
Dim Lastcol As Long
Dim i As Long

With ActiveSheet

Lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = 1 To Lastcol

.Columns(i).Hidden = .Cells(35, i).Value2 = 0
Next i
End With
End Sub

Andybuck86
08-28-2010, 09:02 AM
Perfect - thank you both