I am new to VBA programming and had a doubt which may be quite simple for you.
How do we set a variable in one sub which can be used in another?
I tried using global variable but it didnt work for me. Thank you
Here is an example of how I have created a variable in one sub and used it in another:
Private Sub txtLastName_LostFocus()
FirstName = Me.txtFirstName.Value
LastName = Me.txtLastName.Value
FullName = FirstName & " " & LastName
sayHelloToTheUser (FullName)
End Sub
Private Sub sayHelloToTheUser(name As String)
MsgBox "Hello " & name
End Sub
Essentially, you must pass it through using another sub and having it take the arguments that are necessary. This is the main way that I pass arguments through.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With