Create Toggle Button

young engineer

Board Regular
Joined
Mar 3, 2009
Messages
100
Hi All
I have three toggle buttons hiding/unihiding columns from column F to AW. I am trying to create another button to show columns Q,AH,Al, AD next to each other for a comparison, but it is not working out . It is conflicting with the other hidden columns, and is now hiding other columns.

Please Help!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Heres my code for the buttons.


Private Sub Calendar1_Click()
ActiveCell.Value = CDbl(Calendar1.Value)
ActiveCell.NumberFormat = "mm/dd/yyyy"
ActiveCell.Select
End Sub
Private Sub ToggleButton2_Click()
Dim bool As Boolean
bool = ToggleButton2.Value
If bool Then
ToggleButton2.Caption = "TEG - Show Data"
Else
ToggleButton2.Caption = "TEG - Hide Data"
End If
Columns("s:al").EntireColumn.Hidden = bool

End Sub
Private Sub ToggleButton3_Click()
Dim bool As Boolean
bool = ToggleButton3.Value
If bool Then
ToggleButton3.Caption = "Drumming Data - Show"
Else
ToggleButton3.Caption = "Drumming Data - Hide"
End If
Columns("am:av").EntireColumn.Hidden = bool
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("C:D"), Target) Is Nothing Then
Calendar1.Left = Target.Left + Target.Width - Calendar1.Width
Calendar1.Top = Target.Top + Target.Height
Calendar1.Visible = True
' select Today's date in the Calendar
Calendar1.Value = Date
ElseIf Calendar1.Visible Then Calendar1.Visible = False
End If
End Sub

Private Sub ToggleButton1_Click()
Dim bool As Boolean
bool = ToggleButton1.Value
If bool Then
ToggleButton1.Caption = "Refinery - Show Data"
Else
ToggleButton1.Caption = "Refinery - Hide Data"
End If
Columns("f:g").EntireColumn.Hidden = bool
Columns("j:l").EntireColumn.Hidden = bool
Columns("n:p").EntireColumn.Hidden = bool

End Sub
 
Upvote 0
Private Sub ToggleButton4_Click()
Dim bool As Boolean
bool = ToggleButton4.Value
If bool Then
ToggleButton4.Caption = "QC - Show"
Else
ToggleButton4.Caption = "QC - Hide"
End If
Columns("f:p").EntireColumn.Hidden = bool
Columns("u:ag").EntireColumn.Hidden = bool
Columns("aa:ac").EntireColumn.Hidden = bool
Columns("ai:ak").EntireColumn.Hidden = bool
End Sub

Heres my code for the new button.

It only displays column Q, the rest are still hidden. The other columns AH,AL,AD are not being displayed next to Q at all. They are either hidden or showing up with all the other columns from the sheet.

I think the other button code are conflicting with this one
 
Upvote 0
How about?

Code:
Private Sub ToggleButton4_Click()
    Dim bool As Boolean
    bool = ToggleButton4.Value
    If bool Then
        ToggleButton4.Caption = "QC - Show"
    Else
        ToggleButton4.Caption = "QC - Hide"
    End If
    Columns("f:p").EntireColumn.Hidden = bool
    Columns("q").EntireColumn.Hidden = Not bool
    Columns("r:ac").EntireColumn.Hidden = bool
    Columns("ad").EntireColumn.Hidden = Not bool
    Columns("ae:ag").EntireColumn.Hidden = bool
    Columns("ah").EntireColumn.Hidden = Not bool
    Columns("ai:ak").EntireColumn.Hidden = bool
    Columns("al").EntireColumn.Hidden = Not bool
    Columns("am:av").EntireColumn.Hidden = bool
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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