Second Click on Control Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings!

I made a control button that will unhide a column in a certain range using:

Private Sub CommandButton2_Click()
Columns("B").Select
Selection.EntireColumn.Hidden = False
Range("B1").Select
End Sub

How can I modify this to re-hide the column on the second click, or if it
his already unhidden?
 
Private Sub CommandButton2_Click()
With Columns(2)
.EntireColumn.Hidden = Not .EntireColumn.Hidden
End With
Range("B1").Select
End Sub


Gord Dibben MS Excel MVP
 
Private Sub CommandButton2_Click()
With Columns("B")
.Hidden = Not .Hidden
End With
Range("B1").Select
End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Give this a try...

Private Sub CommandButton2_Click()
With Columns("D")
If .Hidden = True Then
CommandButton2.Caption = "Hide Column"
.Hidden = False
Else
CommandButton2.Caption = "Un-Hide Column"
.Hidden = True
End If
End With
End Sub
 
Thank you!

Gord Dibben said:
Private Sub CommandButton2_Click()
With Columns(2)
.EntireColumn.Hidden = Not .EntireColumn.Hidden
End With
Range("B1").Select
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top