Hi mark and welcome to ExcelForum,
See the attached file for a modified copy of your file which contains the code below.
In your original code below, you were thinking in terms of a spreadsheet formula. All this does is subtract 5 seconds from 20 minutes each and every time you Click.
The following is a first attempt to do what you want. It gets the value from the Cell. It subtracts 5 seconds similar to your formula. It puts the value back in the spreadsheet.
It can be done in one line but it isharder to read and much harder to debug that way.
Unfortunately, this fails and generates a RUNTIME ERROR when going from 5 seconds to ZERO.
Here is the second attempt which 'traps' the error generated above. The items in red are the changes.
Here is a third method that displays the value as text instead of as a Date:
To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. Dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx
Debugger Secrets:
a. Press 'F8' to single step (goes into subroutines and functions).
b. Press SHIFT 'F8' to single step OVER subroutines and functions.
c. Press CTRL 'F8' to stop at the line where the cursor is.
d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
output to the IMMEDIATE WINDOW.
f. Select View > Locals to see all variables while debugging.
g. To automatically set a BREAKPOINT at a certain location put in the line:
'Debug.Assert False'
h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
if i >= 20 and xTV20 > 99.56 then
Debug.Assert False
endif
i. A variable value will be displayed by putting the cursor over the variable name.
To manually set a breakpoint, see http://www.wiseowl.co.uk/blog/s196/breakpoints.htm
--------------
Enjoy.
Lewis
Bookmarks