PC Review


Reply
Thread Tools Rate Thread

Counting using a Button

 
 
New Member
Join Date: Jul 2006
Posts: 4
 
      6th Jul 2006
Hi,

I have placed a button on my worksheet (from the forms toolbar) Each time I click the button, I would like it to it to count: 1,2,3,4 & up to any number. Does anyone know how I might be able to do this?

Thanks

Last edited by iaaw_esmith; 6th Jul 2006 at 06:44 PM..
 
Reply With Quote
 
 
 
 
Member
Join Date: Jun 2006
Posts: 27
 
      14th Jul 2006
Hi

Have a look at Countnum.xls in attached zip file. This counts up to the number you enter, in realtime. If you want to have a max speed count just rem out the application.wait line.

Code:

Sub Countnum()

Dim Countnum As Long
Dim runum As Long
ActiveSheet.Shapes("Button 2").Select
Selection.Characters.Text = 0
Countnum = InputBox("Enter number to count to")
For runum = 1 To Countnum
Selection.Characters.Text = runum
With Selection.Characters(Start:=1, Length:=7).Font
.Size = 20
End With
Application.Wait (Now + TimeValue("0:00:01"))
Next
ActiveCell.Select
End Sub

N.B. You might have trouble identifying the Button 'number' so it might be easier to create a new button via recording a macro and ammend this code to suit

Regards

Zoddy
Attached Files
File Type: zip Countnum.zip (9.4 KB, 16 views)

Last edited by Zoddy; 14th Jul 2006 at 02:19 PM..
 
Reply With Quote
 
Member
Join Date: Jun 2006
Posts: 27
 
      14th Jul 2006
If you want to find out the button number of an existing button use this code in a new Sub

Sub Shape_Index_Name()
Dim myVar As Shapes
Dim shp As Shape
Set myVar = Sheets(1).Shapes
For Each shp In myVar
MsgBox "Index = " & shp.ZOrderPosition & vbCrLf & "Name = " _
& shp.Name
Next
End Sub

Last edited by Zoddy; 14th Jul 2006 at 04:11 PM..
 
Reply With Quote
 
New Member
Join Date: Jul 2006
Posts: 4
 
      17th Jul 2006
That works great thanks...I have one more question for you. Say if I wanted to manually count, so each time I press the button, it will count. For example, press the button once: Print 1....Press it again it will print 2. And so forth. Thanks for all your help!

Take care!
 
Reply With Quote
 
Member
Join Date: Jun 2006
Posts: 27
 
      25th Jul 2006
No Prob - sorry for delay been busy.


Try this code

Sub Manualcount()
Dim runum As Long
ActiveSheet.Shapes("Button 2").Select
runum = Selection.Characters.Text
Selection.Characters.Text = runum + 1
With Selection.Characters(Start:=1, Length:=4).Font
.Size = 20
End With
ActiveCell.Select
End Sub

This will count up with every click on the button

To reset the button to 0 use another button with the code

Sub Reset()
ActiveSheet.Shapes("Button 2").Select
Selection.Characters.Text = 0
ActiveCell.Select
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting items and setting visible status of button magickarle Microsoft Access Form Coding 1 29th May 2008 03:44 PM
Counting, command button and programming in VB =?Utf-8?B?RWxGcm9kbw==?= Microsoft Excel Misc 5 23rd Feb 2007 05:24 AM
Counting how many times a button is pressed =?Utf-8?B?QmVja3k=?= Microsoft Access Forms 3 21st Sep 2006 08:25 PM
counting button koplev@gmail.com Microsoft Excel Misc 1 1st May 2006 03:04 PM
Counting button presses =?Utf-8?B?RUg=?= Microsoft Access VBA Modules 5 4th Aug 2005 07:03 PM


Features
 

Advertising
 

Newsgroups
 


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