Aldin
Aldin

Reputation: 115

vba excel passing parameter from sub to sub

I want to pass my input to other subs,something like:

Sub Search()
  Inputbox myInput   '~> this is the variable I want to pass
  Call getInput      '~> I want to pass the variable to this sub
End sub

Sub getInput()
  if a = myInput     '~> from sub Search()
  DO something
End sub

I search for solution and read about ByVal or ByRef but i get confused where to put the variable, someone can help?

Upvotes: 0

Views: 1647

Answers (1)

GTG
GTG

Reputation: 4954

Sub Search()
  Inputbox myInput   '~> this is the variable I want to pass
  Call getInput (myInput)  '~> Note the variable
End sub

Sub getInput(ByVal inputVar As String)  '~> Note:  You need to specify the datatype
  If a = inputVar Then     '~> Use your parameter here
      'DO something
  End If
End sub

Upvotes: 1

Related Questions