Grouping Select Columns using VBA

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
132
[TABLE="width: 100"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[/TR]
[TR]
[TD]JAN
[/TD]
[TD][/TD]
[TD]FEB
[/TD]
[TD][/TD]
[TD]MAR
[/TD]
[TD][/TD]
[TD]APR
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ACT
[/TD]
[TD][/TD]
[TD]FCST
[/TD]
[TD][/TD]
[TD]BUDGET
[/TD]
[TD][/TD]
[TD]BUDGET
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]X
[/TD]
[TD][/TD]
[TD]X
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Hi All,
I have question. I have a range of columns above. Each month uses two columns (Jan uses both columns A&B ex)
How do I code the above to show only the columns that have the X and hides the other columns?

Thank you
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try:
Code:
Sub HideCols()
    Application.ScreenUpdating = False
    Dim LastRow As Long, x As Long, lCol As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    For x = 1 To lCol
        If Cells(LastRow, x) <> "X" Then
            Columns(x).Hidden = True
        Else
            Columns(x).Hidden = False
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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