Sub addup()
Dim MSht As Variant
Set MSht = Sheets("Sheet2")
With MSht
MTot = .Range("B1") / 28 + .Range("B3")
MyOthertot = (1013 - .Range("B4")) * 28
End With
End Sub
Because I named the sheet in the WITH statement it can go in either
including if you want a general module.
If your using it in conjunction with a userform then you need a method of
calling the code which could be a button on the userform or an event
associated with the userform.
Thanks Mike,
Thats understood. But if I wanted to use a spinbutton(4) which controls the
value of Textbox17 which in turn is linked to Sheet2 cell "B3". Can I insert
this code in spinbutton(4) code?
I hope this demonstrates the basic idea. As spinbutton changes the value is
put into textbox17.
The code I gave you goes in the change event for text box 17 and executes
brcause the value is changing and up dates textbooxes 18 & 19 with the
results of the sum.
Private Sub SpinButton4_Change()
TextBox17.Value = SpinButton4.Value
End Sub
Private Sub TextBox17_Change()
Dim MSht As Variant
Set MSht = Sheets("Sheet2")
With MSht
TextBox18 = .Range("B1") / 28 + .Range("B3")
TextBox19 = (1013 - .Range("B4")) * 28
End With
End Sub
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.