View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Donny Donny is offline
external usenet poster
 
Posts: 11
Default How to get variables from worksheet code to userform code

On Aug 22, 7:54*pm, JLGWhiz wrote:
Public declaration should be made in the standard code module, not the sheet
module.

"Donny" wrote:
Made these changes, unfortunately still won't work.


'Worksheet code--------------


Public Money As Double


Sub StartButton_Click()
Money = 100
End Sub


'Worksheet code--------------


'Userform code--------------------


Public StoreMoney As Double


Sub UserForm_Initialize()
StoreMoney = 0
StoreText = "$" & StoreMoney *'This shows $0 in the Userform text box
End Sub


'Macro that sets the value of StoreMoney to 75


Sub BuyStuff_Click()
MsgBox (Money)
MsgBox (StoreMoney)
If Money = StoreMoney Then
Money = Money - StoreMoney
Sheet1.Range("E9") = Money
Else: OK = MsgBox("You don't have enough money!", vbOKOnly, "Not
enough cash!")
End If
End Sub


'Userform code--------------------


I get three MsgBoxs:
Blank
75
You don't have enough money!


Money variable is still not availible to the userform macro.
In the Userform (general) I wrote: Public Money As Double
This just gives a 0 in the first MsgBox.


Any ideas?


Got it - I guess i've never created a module to put variables or code
in.
That's next to learn. Thanks a bunch!