Arrow081974
New Member
- Joined
- Aug 4, 2018
- Messages
- 3
Hello
I've been trying to write some VBA to set up a toggle button to hide multiple predefined columns.
I initially managed to define the code for the hide/unhide toggle and attached this to a shape
I then wanted a toggle button which would then change the colour of the button and text displayed on the button
What I'm struggling with is combining these into a single piece of code that does both of these actions.
Broadly speaking what I want is
- when columns are hidden I want the toggle button to say "Hidden" and the toggle button to become red with white text
- when columns are not hidden I want the toggle button to say "Not Hidden" and the toggle button to become green with black text
Is anybody able to point me in the right direction? Thanks in advance
I've been trying to write some VBA to set up a toggle button to hide multiple predefined columns.
I initially managed to define the code for the hide/unhide toggle and attached this to a shape
Sub togglecols()
Range("e:e,g:g").EntireColumn.Hidden = Not Range("e:e,g:g").EntireColumn.Hidden
End Sub
I then wanted a toggle button which would then change the colour of the button and text displayed on the button
Private Sub CommandButton1_Click()
With CommandButton1
If .BackColor = vbGreen Then
.BackColor = vbRed
.Caption = "Hidden"
.ForeColor = vbWhite
Else
.BackColor = vbGreen
.Caption = "Unhidden"
.ForeColor = vbBlack
End If
End With
End Sub
What I'm struggling with is combining these into a single piece of code that does both of these actions.
Broadly speaking what I want is
- when columns are hidden I want the toggle button to say "Hidden" and the toggle button to become red with white text
- when columns are not hidden I want the toggle button to say "Not Hidden" and the toggle button to become green with black text
Is anybody able to point me in the right direction? Thanks in advance