Hide & Unhide Columns With Combobox

Excel VBA Display The Selected A Column From Combobox


excel hide column

                 In this template, only the selected column from the combobox is displayed ,other columns are hidden.The used codes in this template :
Private Sub CheckBox1_Click()
ActiveSheet.Cells.EntireColumn.Hidden = False
End Sub

Private Sub ComboBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Me.ComboBox1.DropDown
End Sub

Private Sub UserForm_Initialize()
  Dim lst_column As Integer
    lst_column = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
For j = 2 To lst_column
   ComboBox1.AddItem Split(ActiveSheet.Cells(1, j).Address, "$")(1) & " " & "-" & Cells(1, j).Value
Next j
End Sub

Private Sub ComboBox1_Change()
   Dim lst_column As Integer
lst_column = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
    For j = 2 To lst_column
 
     Columns(Split(ActiveSheet.Cells(1, j).Address, "$")(1)).EntireColumn.Hidden = True
Next j
Columns(ComboBox1.ListIndex + 2).EntireColumn.Hidden = False
End Sub


excel hide unhide columns vba

5 comments:

  1. Please help to download file, i need this function. thank you very much.

    ReplyDelete
    Replies
    1. Download link:https://drive.google.com/file/d/0B-U9DKo5z-PbVzZVaGV0bUV3b3M/view

      Delete
  2. Hi I would like to add 3 column before A how to adjust?

    ReplyDelete
  3. This was lovely thanks for writing this

    ReplyDelete