Toggle Button Color Change When Depressed

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
I have about 30 buttons that I am trying to add a line of code that will change the color of the button when pressed and depressed.

Any ideas?

Code:
Private Sub ToggleButtonAHAJ_Click()
With Columns("AH:AJ")
  If .EntireColumn.Hidden = True Then
     .EntireColumn.Hidden = False
  Else
      .EntireColumn.Hidden = True
  End If
End With
End Sub

Thank you Excel Experts
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Something like
Code:
Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then ToggleButton1.BackColor = vbGreen
End Sub
 
Upvote 0
Hi,
try

Code:
Private Sub ToggleButtonAHAJ_Click()
    With Me.ToggleButtonAHAJ
        Me.Columns("AH:AJ").EntireColumn.Hidden = .Value
        .BackColor = IIf(.Value, vbRed, vbButtonFace)
     End With
End Sub

Change colours as required.

Dave
 
Upvote 0
Try this:
Code:
Sub Hide_Me()
Columns("AH:AJ").Hidden = Not Columns("AH:AJ").Hidden
End Sub








I have about 30 buttons that I am trying to add a line of code that will change the color of the button when pressed and depressed.

Any ideas?

Code:
Private Sub ToggleButtonAHAJ_Click()
With Columns("AH:AJ")
  If .EntireColumn.Hidden = True Then
     .EntireColumn.Hidden = False
  Else
      .EntireColumn.Hidden = True
  End If
End With
End Sub

Thank you Excel Experts
 
Upvote 0
Hi,
try

Code:
Private Sub ToggleButtonAHAJ_Click()
    With Me.ToggleButtonAHAJ
        Me.Columns("AH:AJ").EntireColumn.Hidden = .Value
        .BackColor = IIf(.Value, vbRed, vbButtonFace)
     End With
End Sub

Change colours as required.

Dave

Perfect! All of you, thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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