Trying to Hide a list box with a toggle button

laxstar785

New Member
Joined
Jul 27, 2011
Messages
23
Hi Guys,

I just got some help the other day with my list box on here and now I am trying to hide the list box using a toggle button. Th issue I am having is I can either show and hide the list box using the toggle button. If i do this I can't click the actual list box. If I switch tabs and come back to the tab with the worksheet I can then use the list box but I can't show or hide it until i switch tabs and return again, my code is listed here below any help would be greatly appreciated. (thanks for the help on my list box Mick!).

Code:
Private Sub ToggleButton1_Click()
If ToggleButton1 Then
Sheet2.Shapes("ListBox2").Visible = True
Else
Sheet2.Shapes("ListBox2").Visible = False
End If
End Sub

'This code Enters the Headers into the ListBox
Private Sub Worksheet_Activate()
    With ListBox2
        .List = Application.Transpose(Range("A2:O2").Value)
        .MultiSelect = fmMultiSelectMulti
End With
End Sub

Private Sub CommandButton3_Click()
'Columns Hidden/Unhidden, as per selected headers
Dim Rng As Range
Dim n As Integer
Dim dn As Range
With ListBox2
    For n = 0 To .ListCount - 1
        If .Selected(n) Then
            Columns(n + 1).Hidden = True
        Else
            Columns(n + 1).Hidden = False
        End If
    Next n
End With
If Not Rng Is Nothing Then
   For Each dn In Rng.Columns
  dn.Columns.Hidden = True
 Next dn
End If
End Sub

[End-Code]
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,205
Messages
6,170,731
Members
452,353
Latest member
strainu

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