Set a variable in one sub and use in another

I am new to VBA programming and doubt it can be quite simple for you.

How do we set a variable in one sub that can be used in another?

I tried using a global variable, but that didn't help me. thank you

+4
source share
1 answer

Here is an example of how I 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 should pass it using another sub and require the necessary arguments. This is the main way to pass arguments through.

+7
source

Source: https://habr.com/ru/post/1494779/


All Articles