ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Button (https://www.excelbanter.com/excel-programming/338919-toggle-button.html)

Dave_2k5[_7_]

Toggle Button
 

Hi all,

I am looking a putting a VB command button on one of my sheets, which
when pressed once it does one thing, then when pressed again it does
something different.

e.g. when pressed first time it hides a range of rows, when pressed
again it unhides them.

Hope you can help

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=401061


dominicb[_107_]

Toggle Button
 

Good morning Dave_2k5

Why not set up a check box from the control toolbox toolbar. Once
you've drawn it on screen double click on it and paste the code below
into the window that opens. Close the window to return to Excel and on
the Control Toolbox bar select Design Mode (top left) to set the
checkbox.

The code shown assumes that your checkbox will be called Checkbox1 and
that you want to hide rows 10 to 15 inclusive.

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Rows("10:15").EntireRow.Hidden = True
Else
Rows("10:15").EntireRow.Hidden = False
End If
End Sub

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=401061


Dave_2k5[_8_]

Toggle Button
 

I would do that......But want it to be a button not a checkbox!!

Cheers Anyway

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile: http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=401061


William[_2_]

Toggle Button
 
Hi Dave

Range("F12:F46").EntireRow.Hidden = _
Not Range("F12:F46").EntireRow.Hidden

--


XL2003
Regards

William



"Dave_2k5" wrote in
message ...

Hi all,

I am looking a putting a VB command button on one of my sheets, which
when pressed once it does one thing, then when pressed again it does
something different.

e.g. when pressed first time it hides a range of rows, when pressed
again it unhides them.

Hope you can help

Dave


--
Dave_2k5
------------------------------------------------------------------------
Dave_2k5's Profile:
http://www.excelforum.com/member.php...o&userid=19667
View this thread: http://www.excelforum.com/showthread...hreadid=401061





dominicb[_108_]

Toggle Button
 

Hi Dave

If it HAS to be a button then have a look in the control toolbox -
there is a toggle button. Don't use the forms toolbar because there
isn't one there.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=401061



All times are GMT +1. The time now is 12:37 PM.

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