Spinner and Date What the heck is happening?

G

Guest

It seemed pretty simple, drop a spinner on the worksheet, stick some code
into the spinup and spindown to add or subtract 1 to/from the value in a
certain cell. Just because the value is a date shouldn't make any difference,
after all it's just another number.
So why does this retrieve the value of Zero everytime it fires? Yea, I put
the current date into the cell F5, then when I click on the spinup the value
in F5 becomes Zero! And of course it puts the Zero value +1 back into the
cell.
What the heck is heck is going on?! :/)

Private Sub SpinButton1_SpinDown()
Range("F5").Value = DateValue(Range("F5").Value) - 1
End Sub

Private Sub SpinButton1_SpinUp()
Range("F5").Value = DateValue(Range("F5").Value) + 1
End Sub
 
G

Guest

Not sure, your code works just fine for me.

Is F5 formatted to be a date? This code works just as well too,

Private Sub SpinButton1_SpinDown()
Range("F5").Value = Range("F5").Value - 1
End Sub
Private Sub SpinButton1_SpinUp()
Range("F5").Value = Range("F5").Value + 1
End Sub


h.
 
B

Bernie Deitrick

Mike,

Dates are just formatted numbers, with 1 being one day. This should work:

Private Sub SpinButton1_SpinDown()
Range("F5").Value = Range("F5").Value - 1
End Sub

Private Sub SpinButton1_SpinUp()
Range("F5").Value = Range("F5").Value + 1
End Sub

HTH,
Bernie
MS Excel MVP
 
G

Guest

Well now that is just plain wierd. I went back and tried it again and it
worked just fine. Sometimes I think the computer doesn't like me.

Thanks folks.
 

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