1 Userbutton to perform alternating functions

S

Steve

Hi

I'm wondering how I do this:

I want one userbutton on a spreadsheet where, if columns D - H are
hidden, the button unhides them, or if they are visible it hides them.

Does anyone have any advice, please?

Thanks in advance

Steve
 
S

Stefi

Insert this line in the button's code module:
Columns("D:H").EntireColumn.Hidden = Not Columns("D:H").EntireColumn.Hidden

Regards,
Stefi

„Steve†ezt írta:
 
K

Ken Johnson

Hi

I'm wondering how I do this:

I want one userbutton on a spreadsheet where, if columns D - H are
hidden, the button unhides them, or if they are visible it hides them.

Does anyone have any advice, please?

Thanks in advance

Steve

ActiveSheet.Range("D:H").EntireColumn.Hidden = Not
(ActiveSheet.Range("D:H").EntireColumn.Hidden)

Ken Johnson
 
K

Ken Johnson

ActiveSheet.Range("D:H").EntireColumn.Hidden = Not
(ActiveSheet.Range("D:H").EntireColumn.Hidden)

Ken Johnson

But this is neater...

With ActiveSheet.Columns("D:H")
.Hidden = Not .Hidden
End With

Ken Johnson
 
M

Mike H

Steve,

You could also change the button caption

Private Sub CommandButton1_Click()
With ActiveSheet.Columns("D:H")
.Hidden = Not .Hidden
If .Hidden Then
CommandButton1.Caption = "Show"
Else
CommandButton1.Caption = "Hide"
End If
End With
End Sub

Mike
 

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

Top