ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how do I set up a counter? (https://www.excelbanter.com/excel-discussion-misc-queries/115176-how-do-i-set-up-counter.html)

John T

how do I set up a counter?
 
I want to set up a cell which counts how many times a macro button has
been clicked. It also nees to be re-setable - presumably using
another macro.

Any suggestions

Cheers

John Taylor
"John Taylor's Freebies"
www.johnandgwyn.co.uk
(a free, teachers' resource website)

If replying by email take out "therubbish"

Chip Pearson

how do I set up a counter?
 
Use code like the following:

Sub IncrementCounter()
With ThisWorkbook.Worksheets("Sheet1").Range("A1") '<<< CHANGE
.Value = .Value + 1
End With
End Sub

Sub ResetCounter()
ThisWorkbook.Worksheets("Sheet1").Range("A1").Valu e = 0
End Sub

Assign IncrementCounter to your macro button, or call the function from the
code already attached to the button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


"John T" wrote in message
...
I want to set up a cell which counts how many times a macro button has
been clicked. It also nees to be re-setable - presumably using
another macro.

Any suggestions

Cheers

John Taylor
"John Taylor's Freebies"
www.johnandgwyn.co.uk
(a free, teachers' resource website)

If replying by email take out "therubbish"




John T

how do I set up a counter?
 


Thanks for your help - it looks as though I'm going to have to do some
studying - never come across "Sub" or "code" before - presumably it's
a bit like defining procedures in old-fashioned BASIC.

I've just tried to find "sub" and "code in Steve Johnson's "Brilliant
Excel 2003" (published by Pearson Books) - not there!

Cheers

John T


t On Thu, 19 Oct 2006 13:34:51 -0500, "Chip Pearson"
wrote:

Use code like the following:

Sub IncrementCounter()
With ThisWorkbook.Worksheets("Sheet1").Range("A1") '<<< CHANGE
.Value = .Value + 1
End With
End Sub

Sub ResetCounter()
ThisWorkbook.Worksheets("Sheet1").Range("A1").Valu e = 0
End Sub

Assign IncrementCounter to your macro button, or call the function from the
code already attached to the button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


"John T" wrote in message
...
I want to set up a cell which counts how many times a macro button has
been clicked. It also nees to be re-setable - presumably using
another macro.

Any suggestions

Cheers

John Taylor
"John Taylor's Freebies"
www.johnandgwyn.co.uk
(a free, teachers' resource website)

If replying by email take out "therubbish"





John T

how do I set up a counter?
 

Wow I've just learnt hoe to use code! (sort of)
I've pasted your text in and adapted it and it works - MANY THANKS

Is it possible to make a count down timer - i.e. counting seconds down
to zero?

Cheers

John T


On Thu, 19 Oct 2006 13:34:51 -0500, "Chip Pearson"
wrote:

Use code like the following:

Sub IncrementCounter()
With ThisWorkbook.Worksheets("Sheet1").Range("A1") '<<< CHANGE
.Value = .Value + 1
End With
End Sub

Sub ResetCounter()
ThisWorkbook.Worksheets("Sheet1").Range("A1").Valu e = 0
End Sub

Assign IncrementCounter to your macro button, or call the function from the
code already attached to the button.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


"John T" wrote in message
...
I want to set up a cell which counts how many times a macro button has
been clicked. It also nees to be re-setable - presumably using
another macro.

Any suggestions

Cheers

John Taylor
"John Taylor's Freebies"
www.johnandgwyn.co.uk
(a free, teachers' resource website)

If replying by email take out "therubbish"






All times are GMT +1. The time now is 11:24 PM.

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