Please help - Spin Button

T

the nomad

Dear Experts,

Can you please help me to write the code for the following.

In Cell "A1" I have a value, e.g. 3
In Cell "B1" I have an equation with the value in "A1", e.g.
=SQRT("A1"^2+2.5*"A1"-1.4)

I also have a Spin Button that I want to use to increase
SpinButton1_SpinUp() or decrease SpinButton1_SpinUp() the value in A1 with
an increment of 1 every time I click Up or Down so that the calculation in
B1 would change. But I want this value to be saved in A1 as well when I exit
Excel and open again.

Thanks a lot!

Cheers,
Ginger
 
B

Bernard Liengme

You formula is correct expect you do not need quotes
=SQRT(A1^2+2.5*A1-1.4)

Do you have the spin button working?
Excel will keep whatever value is in A1 at the time you issue the Save
command

best wishes
 
T

the nomad

Bernard,

Thank you for you reply. I put the quotes just to emphasize that it is
referenced to A1. Could you please help me with the code when I press up
button on Spin Button, the value in A1 increases by one, and the opposite -
if I press down button, the value decreases by 1, so the calculation of f(x)
equation
in B1 will be based on a new x value in A1.

Thanks a lot!
Ginger

~~~
great minds think alike
 
O

Office_Novice

This should get you started...

Option Explicit

Private Sub SpinButton1_SpinDown()
' If "A1" is Greater then 0 the "A1"-1
With Range("a1")
If .Value > "0" Then
.Value = .Value - 1
ElseIf .Value <= "0" Then ' if 0 then do nothing
Exit Sub
End If
End With
End Sub

Private Sub SpinButton1_SpinUp()
' If "A1" is Greater then 0 "a1" + 1
With Range("a1")
If .Value > "0" Then
.Value = .Value + 1
ElseIf .Value <= "0" Then ' If 0 then do nothing
Exit Sub
End If
End With
End Sub
 
T

the nomad

It is so amazing when it works! Are you sure you are Office Novice? :))

Thanks a lot

Ginger
 
B

Bernard Liengme

If you used a Form spinner (not Control) you could link it to A1 without
code
Want me to send you a file?
best wishes
 
T

the nomad

Bernard,

I did some "research" and found it myself, much easier than what I
thought... Thank you for the idea!!!

Regards,
Ginger
 

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