Defining Variables that pass to other Subs

J

JasonSelf

I have two Subs, in the first I define a variable and in the second I
recall this variable. here is how I am trying to do it (its not
working)


Private Sub TaskBox_Change()
Dim Task As String
Task = TaskBox.Value
End Sub

Public Sub Next()
ActiveCell.FormulaR1C1 = Task
End Sub

This is just a basic representation that I am trying to show of what is
not working. I can not figure out how I am to get the Variable defined
in the Sub "TaskBox_Change" passed to the Sub "Next"

Any help or guidance would be greatly appreciated.
 
K

kkknie

Here's how:

Define the variable on a module level. You code would read:

Dim Task As String

Private Sub TaskBox_Change()
Task = TaskBox.Value
End Sub

Public Sub Next()
ActiveCell.FormulaR1C1 = Task
End Sub

Any variable defined inside of a Sub is only available in that sub.
 

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