ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   1 Userbutton to perform alternating functions (https://www.excelbanter.com/excel-discussion-misc-queries/207166-1-userbutton-perform-alternating-functions.html)

Steve[_11_]

1 Userbutton to perform alternating functions
 
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

Stefi

1 Userbutton to perform alternating functions
 
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:

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


Ken Johnson

1 Userbutton to perform alternating functions
 
On Oct 21, 8:37*pm, Steve wrote:
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

Ken Johnson

1 Userbutton to perform alternating functions
 
On Oct 21, 8:54*pm, Ken Johnson wrote:
On Oct 21, 8:37*pm, Steve wrote:

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


But this is neater...

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

Ken Johnson

Mike H

1 Userbutton to perform alternating functions
 
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

"Steve" wrote:

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



All times are GMT +1. The time now is 07:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com