Hide Columns Based On Cell Value

bboysen

New Member
Joined
Aug 6, 2010
Messages
44
Hey guys,

I know there has been many post on the good old internet about this but i can find one that will fix my issue.
What i am trying to do is hide Columns based on a valve that can fall in any row in the column.

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Hide[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dont Hide[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD]Dont Hide[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Hide[/TD]
[TD][/TD]
[TD]Dont Hide[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Hide[/TD]
[TD][/TD]
[TD][/TD]
[TD]Hide[/TD]
[TD]Hide[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Dont Hide[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Above is an example of what my spread sheet looks like. In this case i want to be able to hide all of the columns with the Hide comment in it. The hard part is this is how my data looks on all of my sheets.

The code that i have from a previous hide vba i built is this
Code:
Sub HideCol()

Dim Column As Long


With ActiveSheet
On Error Resume Next
On Error GoTo 0
For Column = 1 To 29
If Application.CountA(.Range(.Cells(2, Column), Cells(65536, Column))) = 0 Then
.Columns(Column).Hidden = True
End If
Next Column


End With
End Sub

I have tried to modify the = 0 Then to make it have = "Hide" Then but with no luck to it working.

Any help would be great. Thanks in advance.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Code:
Sub HideCol()
Dim Column As Long
With ActiveSheet
      For Column = 1 To 29
      If Application.CountIf(.Range(.Cells(2, Column), .Cells(Rows.Count, Column)), "Hide") <> 0 Then _
            .Columns(Column).Hidden = True
      Next Column
End With
End Sub
 
Upvote 0
Code:
Sub HideCol()
Dim Column As Long
With ActiveSheet
      For Column = 1 To 29
      If Application.CountIf(.Range(.Cells(2, Column), .Cells(Rows.Count, Column)), "Hide") <> 0 Then _
            .Columns(Column).Hidden = True
      Next Column
End With
End Sub

Boller you are the best. Thanks for the help you did just what i needed.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top