Hide columns if specific cell is blank?

S

smduello

I found a Macro, but I am having trouble modifying it to auto-hide the
column if a certain cell is empty. ie. I have blank columns that
serve as spaces between the next grouping of data and its hiding
everything. Basically, I want to say hide if a certain cell has a 0
(zero) in it. Any ideas?


Option Explicit
Sub hideCols()


Dim iCol As Long


With ActiveSheet
For iCol = 1 To .Cells(1, .Columns.Count).End(xlToLeft).Column
If Application.CountA( _
.Cells(2, iCol).Resize(.Rows.Count - 1)) = 0 Then
.Columns(iCol).Hidden = True
Else
.Columns(iCol).Hidden = False
End If
Next iCol
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top