View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1709_] Rick Rothstein \(MVP - VB\)[_1709_] is offline
external usenet poster
 
Posts: 1
Default Hiding columns based on value

Did you want the hiding action to be dynamic (in other words, as soon as the
completing 'X' is placed)?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Long
Dim Contents As String
With Target
If Not Intersect(Target, Range("E3:EO12")) Is Nothing Then
For X = 3 To 12
Contents = Contents & Cells(X, .Column).Value
Next
If UCase(Contents) = "XXXXXXXXXX" Then .EntireColumn.Hidden = True
End If
End With
End Sub

Or did you want it as a "when I activate it" type macro?

Sub HideColumns()
Dim X As Long, Z As Long
Dim Contents As String
For Z = 5 To 145
Contents = ""
For X = 3 To 12
Contents = Contents & Cells(X, Z).Value
Next
If UCase(Contents) = "XXXXXXXXXX" Then
Cells(1, Z).EntireColumn.Hidden = True
End If
Next
End Sub

Rick


"turbogreg17" wrote in message
...
Please help, Ive searched for the answer, but my problem seems to be
unique.
Here is the background: I have a spreadsheet with many, many columns of
data
(€œE€ through €œEO€ as of today, and it keeps growing). I have 9 rows of
data
(rows 3 -12), so the area Im concerned with as of today spans E3:EO12.
The
cells are either blank or contain a €œX€ (just two choices).
I want to hide every column that contains an €œX€ in each of its rows (i.e.
if every cell in €œE3:E12€ contains €œX€, then hide €œE€, same for column €œF€,
€œG€, etc.). If any one of the rows in a column is blank, I need to see
the
column. I just cant get the syntax right for the macro.
I thought about redoing the macro code for each column, but there has to
be
a better way. And it would be a bit cumbersome as I continue to add
columns.
Can someone please help? Thanks. Greg