Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 49
Default Help with toggling display

Hi,

I have a cell which has a defined name "status". It currently displays the
word, "Off". On clicking a button I want it to toggle from "Off" to "On"
and vice versa. Any help is much appreciated.

TIA
Tom


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 915
Default Help with toggling display

Tom wrote:
Hi,

I have a cell which has a defined name "status". It currently displays the
word, "Off". On clicking a button I want it to toggle from "Off" to "On"
and vice versa. Any help is much appreciated.

TIA
Tom



Add a VB command button to the worksheet (accessible from the Visual
Basic toolbar's toolbox). (This is not the same as a Form button -- you
can use that as well but the steps are a little different.)

With the worksheet in design mode (should be already), double click the
new button to reveal the empty sub:

Private Sub CommandButton1_Click()

Add this code:

Private Sub CommandButton1_Click()
If Range("Status").Value = "On" Then
Range("Status").Value = "Off"
ElseIf Range("Status").Value = "Off" Then
Range("Status").Value = "On"
End If
End Sub

Return to the worksheet, turn off design mode (the triangle/ruler/pencil
widget) and try out your new button.
  #3   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 49
Default Help with toggling display

That was great. Thanks smartin.

"smartin" wrote in message
...
Tom wrote:
Hi,

I have a cell which has a defined name "status". It currently displays
the word, "Off". On clicking a button I want it to toggle from "Off" to
"On"
and vice versa. Any help is much appreciated.

TIA
Tom


Add a VB command button to the worksheet (accessible from the Visual Basic
toolbar's toolbox). (This is not the same as a Form button -- you can use
that as well but the steps are a little different.)

With the worksheet in design mode (should be already), double click the
new button to reveal the empty sub:

Private Sub CommandButton1_Click()

Add this code:

Private Sub CommandButton1_Click()
If Range("Status").Value = "On" Then
Range("Status").Value = "Off"
ElseIf Range("Status").Value = "Off" Then
Range("Status").Value = "On"
End If
End Sub

Return to the worksheet, turn off design mode (the triangle/ruler/pencil
widget) and try out your new button.



  #4   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 49
Default Help with toggling display

I've just moved the macro from the Personal worksheet to its own worksheet
and attached it to a button. Now it has stopped working. Weird. Any
suggestion how I can get it to work again?

Tom

"smartin" wrote in message
...
Tom wrote:
Hi,

I have a cell which has a defined name "status". It currently displays
the word, "Off". On clicking a button I want it to toggle from "Off" to
"On"
and vice versa. Any help is much appreciated.

TIA
Tom


Add a VB command button to the worksheet (accessible from the Visual Basic
toolbar's toolbox). (This is not the same as a Form button -- you can use
that as well but the steps are a little different.)

With the worksheet in design mode (should be already), double click the
new button to reveal the empty sub:

Private Sub CommandButton1_Click()

Add this code:

Private Sub CommandButton1_Click()
If Range("Status").Value = "On" Then
Range("Status").Value = "Off"
ElseIf Range("Status").Value = "Off" Then
Range("Status").Value = "On"
End If
End Sub

Return to the worksheet, turn off design mode (the triangle/ruler/pencil
widget) and try out your new button.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A toggling border macro Tom Excel Discussion (Misc queries) 10 May 26th 09 12:59 PM
Toggling Visibility of items with VBA SpielbergRules Excel Worksheet Functions 3 July 2nd 06 06:12 PM
toggling jlofritts Excel Worksheet Functions 3 March 7th 06 06:34 PM
Toggling autofit rgarber50 Excel Discussion (Misc queries) 2 September 4th 05 07:40 AM
AutoFilter toggling in VBA (How to use correctly) Dennis Excel Discussion (Misc queries) 1 June 25th 05 08:43 PM


All times are GMT +1. The time now is 09:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"