Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Store cell value and set to zero

The question is a 'set to zero' and 'reset to the previous' problem

I have a cell with anything inside (say A1=23). With a set button I want to
change the value of A1 to 0, and then repushing the button I want to get back
23 in A1. Is it possible? And what if there is a formula in the cell?

all my best..


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Store cell value and set to zero

First enter the following macro into a standard module:

Public storeIt As Variant
Sub flipFlop()
With Range("A1")
If .Value = 0 Then
.Value = storeIt
Else
storeIt = .Value
.Value = 0
End If
End With
End Sub

Then create a button in the usual way and assign the macro to it.
--
Gary''s Student - gsnu200778


"noyau" wrote:

The question is a 'set to zero' and 'reset to the previous' problem

I have a cell with anything inside (say A1=23). With a set button I want to
change the value of A1 to 0, and then repushing the button I want to get back
23 in A1. Is it possible? And what if there is a formula in the cell?

all my best..


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Store cell value and set to zero


Unfortunately I was enable to call back the previous value.


The program that I use for the button is the following one; but as you see
there is only 0 and a fixed (unchangeable) value to call back


Private Sub CommandButton2_Click()
If CommandButton2.Caption = "Running" Then
Range("a1").Value = 0
CommandButton2.Caption = "Shutdown"
CommandButton2.BackColor = &HFF&
'Range("b2;b3").Copy Destination: Range ("b4")
Else
Range("a1").Value = 5.4
CommandButton2.Caption = "Running"
CommandButton2.BackColor = &HFF00&
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Store cell value and set to zero

We are making excellent progress!

Calling back the value that was in A1 requires storing it in a public,
static, location. If you use a variable in the macro, VBA "forgets" its
value each time the button is pressed. Therefore, from Excel:


1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste in the following single line:
Public flipflop as Variant
4. lose the VBE window


Then update your code as follows:

Private Sub CommandButton2_Click()
If CommandButton2.Caption = "Running" Then
flipflop = Range("a1").value
Range("a1").Value = 0
CommandButton2.Caption = "Shutdown"
CommandButton2.BackColor = &HFF&
'Range("b2;b3").Copy Destination: Range ("b4")
Else
Range("a1").Value = flipflop
CommandButton2.Caption = "Running"
CommandButton2.BackColor = &HFF00&
End If
End Sub




--
Gary''s Student - gsnu200778


"noyau" wrote:


Unfortunately I was enable to call back the previous value.


The program that I use for the button is the following one; but as you see
there is only 0 and a fixed (unchangeable) value to call back


Private Sub CommandButton2_Click()
If CommandButton2.Caption = "Running" Then
Range("a1").Value = 0
CommandButton2.Caption = "Shutdown"
CommandButton2.BackColor = &HFF&
'Range("b2;b3").Copy Destination: Range ("b4")
Else
Range("a1").Value = 5.4
CommandButton2.Caption = "Running"
CommandButton2.BackColor = &HFF00&
End If
End Sub

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
store inventory sheet(ex:sports equipment store) vardan Excel Worksheet Functions 1 October 11th 06 12:51 AM
Store formula in Cell ggant Excel Discussion (Misc queries) 3 December 14th 05 08:11 PM
Store formula in Cell CLR Excel Discussion (Misc queries) 0 December 14th 05 05:45 PM
Store max value of changing cell q5 Excel Worksheet Functions 0 July 22nd 05 04:05 AM
store some of the information from one cell into another bsantona Excel Discussion (Misc queries) 1 February 10th 05 02:35 PM


All times are GMT +1. The time now is 10:18 PM.

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

About Us

"It's about Microsoft Excel"