View selected columns in Excel using VBA

Contributor

I am considering of viewing the Q1 (Jan to Mar), Q2 (Jan to June), Q3 (Jan to Sep) and Q4 (Jan tro Dec) ufor Target and Actual months using VBA. The below does not work. Please advise


Cells.Select
Selection.EntireColumn.Hidden = False
Selection.EntireColumn.Hidden = False
Columns("I:Q").Select
Selection.EntireColumn.Hidden = True
Columns("V:AD").Select
Selection.EntireColumn.Hidden = True
End Sub
Sub view2()
'
' view2 Macro
'

'
Cells.Select
Selection.EntireColumn.Hidden = False
Columns("L:Q").Select
Selection.EntireColumn.Hidden = True
Columns("Y:AD").Select
Selection.EntireColumn.Hidden = True
End Sub

3 Replies

@Chan_Tze_Leong 

Here is a small example with the month of January, you could extend this to the other months and develop it further.

 

Hope to have helped you with this.

 

NikolinoDE

I know I don't know anything (Socrates)

Hi! Could you please share the VBA code?

@Chan_Tze_Leong 

Here is the VBA code, you just have to create a new button for each month and show/hide the columns accordingly.

 

Option Explicit
Private Sub CommandButton1_Click() ' To Show ONLY your Janaury Columns
'Me.Unprotect ("yourpass")
Application.ScreenUpdating = False
With ActiveSheet
    .Range("E:AS").EntireColumn.Hidden = True  ' Displays the month of January ONLY
   
    .Range("F:F, S:S").EntireColumn.Hidden = False   'Always Unhides All your Columns from your previous action
End With
Application.ScreenUpdating = True
'Me.Protect ("yourpass")
End Sub

 

 

 Hope I was able to help you with this information.

 

NikolinoDE

I know I don't know anything (Socrates)