Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Run Different Macros for the Up & Down Spinner Form Buttons

How do I assign different macros to up & down spinner buttons?
I want to imporve on the standard up/down by integers the standard
control offers by writing some code myself, but I can only assign a
macro to the whole control (Up & Down)

Cheers
Tony
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Run Different Macros for the Up & Down Spinner Form Buttons

Compare the current value with the last value that you had stored, eg in
some cell or in a Name, then update the last value.

Assign "SpinnerTest" as macro to a Spinner from the Forms toolbar.

Sub SpinnerTest()
Dim val As Long
Dim sp As Spinner
Dim rLastVal As Range

Set rLastVal = Range("A1")

Set sp = ActiveSheet.Spinners(Application.Caller)
' or if only applicable to one spinner
' Set sp = ActiveSheet.Spinners("Spinner 1")

With sp
If Len(rLastVal.Value) = 0 Then
rLastVal = .Value
MsgBox "Initialising " & .Value
ElseIf .Value = rLastVal Then
MsgBox "Still at " & IIf(.Value = .Min, "Min:" & .Min, "Max:" &
..Max)
ElseIf .Value rLastVal Then
MsgBox "Going up " & .Value, , "Last " & rLastVal
Else
MsgBox "Going down " & .Value, , "Last " & rLastVal
End If
rLastVal = .Value
End With

End Sub

Regards,
Peter T

"bony_tony" wrote in message
...
How do I assign different macros to up & down spinner buttons?
I want to imporve on the standard up/down by integers the standard
control offers by writing some code myself, but I can only assign a
macro to the whole control (Up & Down)

Cheers
Tony



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Run Different Macros for the Up & Down Spinner Form Buttons

Thanks.
I didn't really want to store any values in the sheet.
I've just noticed I have some "ActiveX" controls where I could use
"ScrollBar1_KeyUp". I have Excel 2007. Will this work with Excel 97+?

Cheers
Tony

On Apr 17, 12:21*pm, "Peter T" <peter_t@discussions wrote:
Compare the current value with the last value that you had stored, eg in
some cell or in a Name, then update the last value.

Assign "SpinnerTest" as macro to a Spinner from the Forms toolbar.

Sub SpinnerTest()
Dim val As Long
Dim sp As Spinner
Dim rLastVal As Range

* * Set rLastVal = Range("A1")

* * Set sp = ActiveSheet.Spinners(Application.Caller)
* * ' or if only applicable to one spinner
* * ' Set sp = ActiveSheet.Spinners("Spinner 1")

* * With sp
* * * * If Len(rLastVal.Value) = 0 Then
* * * * * * rLastVal = .Value
* * * * * * MsgBox "Initialising " & .Value
* * * * ElseIf .Value = rLastVal Then
* * * * * * MsgBox "Still at " & IIf(.Value = .Min, "Min:" & .Min, "Max:" &
.Max)
* * * * ElseIf .Value rLastVal Then
* * * * * * MsgBox "Going up " & .Value, , "Last " & rLastVal
* * * * Else
* * * * * * MsgBox "Going down " & .Value, , "Last " & rLastVal
* * * * End If
* * * * rLastVal = .Value
* * End With

End Sub

Regards,
Peter T

"bony_tony" wrote in message

...



How do I assign different macros to up & down spinner buttons?
I want to imporve on the standard up/down by integers the standard
control offers by writing some code myself, but I can only assign a
macro to the whole control (Up & Down)


Cheers
Tony- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Run Different Macros for the Up & Down Spinner Form Buttons

As I mentioned you could store the last value in a Name (named formula)
rather than in a cell. Alternatively you could store in a static variable in
your project, it would only need to be initialized first time in a session.

Yes Excel 97+ have ScrollBar1_KeyUp and SpinButton1_KeyUp (as you originally
asked about a spinner). Although these events will indicate an arrow press,
say vbkeyup or vbkeydown, they won't indicate if mouse clicked up/down.

Regards,
Peter T

"bony_tony" wrote in message
...
Thanks.
I didn't really want to store any values in the sheet.
I've just noticed I have some "ActiveX" controls where I could use
"ScrollBar1_KeyUp". I have Excel 2007. Will this work with Excel 97+?

Cheers
Tony

On Apr 17, 12:21 pm, "Peter T" <peter_t@discussions wrote:
Compare the current value with the last value that you had stored, eg in
some cell or in a Name, then update the last value.

Assign "SpinnerTest" as macro to a Spinner from the Forms toolbar.

Sub SpinnerTest()
Dim val As Long
Dim sp As Spinner
Dim rLastVal As Range

Set rLastVal = Range("A1")

Set sp = ActiveSheet.Spinners(Application.Caller)
' or if only applicable to one spinner
' Set sp = ActiveSheet.Spinners("Spinner 1")

With sp
If Len(rLastVal.Value) = 0 Then
rLastVal = .Value
MsgBox "Initialising " & .Value
ElseIf .Value = rLastVal Then
MsgBox "Still at " & IIf(.Value = .Min, "Min:" & .Min, "Max:" &
.Max)
ElseIf .Value rLastVal Then
MsgBox "Going up " & .Value, , "Last " & rLastVal
Else
MsgBox "Going down " & .Value, , "Last " & rLastVal
End If
rLastVal = .Value
End With

End Sub

Regards,
Peter T

"bony_tony" wrote in message

...



How do I assign different macros to up & down spinner buttons?
I want to imporve on the standard up/down by integers the standard
control offers by writing some code myself, but I can only assign a
macro to the whole control (Up & Down)


Cheers
Tony- Hide quoted text -


- Show quoted text -



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
How do I get 2003 Macros and Toolbar Buttons form Excel 2003 to 20 Scott Sornberger New Users to Excel 2 March 19th 08 11:42 AM
Maximum number in Form Spinner Control ? Darrell Burnett Excel Worksheet Functions 3 March 5th 08 12:49 AM
Exporting excel charts with form controls (spinner) to Powerpoint Mike B Charts and Charting in Excel 1 November 18th 07 04:10 PM
Form buttons and macros cadbury Excel Programming 1 November 12th 03 03:56 AM
Format of a textbox on a user form controled by a spinner Jeff[_20_] Excel Programming 1 September 9th 03 05:09 AM


All times are GMT +1. The time now is 12:19 AM.

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

About Us

"It's about Microsoft Excel"