Why wont this work?....Ontime + Now

S

SuitedAces

*Please help with this*, I am using 2 button presses to swap ranges
( I have 30 ranges and 30 buttons)
and I am using Ontime to kill and reset the code if the user doesn't
press the second button within 4 seconds of the first button press.

They way I am using the Ontime function is taken directly
out of EXCEL help yet it results in .... unable to find the function
(ResetTheFirstManualSwapButton)

I only am setting the values in B2 just to watch the results of the
flow of the code before I add the code needed to do the swapping

************************************************** *****
Public Sub ManualSwap(SwapPosition As Integer)

If FirstButtonPress = 0 Then

FirstButtonPress = SwapPosition
Range("B2").Select
Selection.Value = FirstButtonPress
'give the user 4 seconds to choose the second range in the swap
'Application.OnTime Now + TimeValue("00:00:4"),
ResetTheFirstManualSwapButton

Else

'There are now 2 variables for the 2 ranges
'run some code here to swap the ranges
'set the to FirstButtonPress = 0 ready for the next swap
FirstButtonPress = 0
Range("B2").Select
Selection.Value = FirstButtonPress

End If

End Sub
************************************************** *****
Public Function ResetTheFirstManualSwapButton()
' the user waited too long so reset the to FirstButtonPress = 0
Dim FirstButtonPress As Integer
FirstButtonPress = 0
Range("B2").Select
Selection.Value = FirstButtonPress
End Function

If I can get past this obstacle I will be able to complete the code for
these
swap buttons. *Your help is appreciated*
 
B

Bob Phillips

Haven't tested this but the OnTime macro is a string, not a direct
reference

Public Sub ManualSwap(SwapPosition As Integer)

If FirstButtonPress = 0 Then

FirstButtonPress = SwapPosition
Range("B2").Select
Selection.Value = FirstButtonPress
'give the user 4 seconds to choose the second range in the swap
Application.OnTime Now + TimeValue("00:00:4"), _
"ResetTheFirstManualSwapButton"

Else

'There are now 2 variables for the 2 ranges
'run some code here to swap the ranges
'set the to FirstButtonPress = 0 ready for the next swap
FirstButtonPress = 0
Range("B2").Select
Selection.Value = FirstButtonPress

End If

End Sub
'************************************************** *****
Public Function ResetTheFirstManualSwapButton()
' the user waited too long so reset the to FirstButtonPress = 0
Dim FirstButtonPress As Integer
FirstButtonPress = 0
Range("B2").Select
Selection.Value = FirstButtonPress
End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
B

Bob Phillips

I didn't say a macro string, I said the macro passed to OnTime is passed as
a string

Application OnTime, earliest_time, "procedure_to_run"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top