Spin Button Alternative?

eddiev1972

New Member
Joined
Mar 22, 2010
Messages
38
This is more of a VBA learning exercise than anything else:

I want to be able to create button that will continuosly increment/decrement a value while the button is depressed. (Similar to how a spin button works.)

This is primarily because a button will allow you to put a picture on it and spin button (seemingly) doesn't

I have tried the mousedown event and it will increment the value once. So there is either something I don't understand with the event, or I have ommitted the code needed for continuous function.

Any thoughts? Is this possible?

Thank you in advance for any guidance.
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try this:-
"A1" is incremented by 1 until you lift your finger from the commandButton , When The "MouseUp" event triggers and "a1" is returned to "1"
Code:
Option Explicit
Dim Go As String
Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Go = "Go"
Do While Go = "Go"
DoEvents
[a1] = [a1] + 1
Loop
End Sub
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Go = "Stop"
[a1] = 0
End Sub
Mick
 

Watch MrExcel Video

Forum statistics

Threads
1,109,027
Messages
5,526,329
Members
409,696
Latest member
EERS

This Week's Hot Topics

Top