excelvbastringcallinputbox

Pass Input Box variable from one sub to another


I was reading a post by another where the need for a Global declaration wasn't needed.

I have a Sub asking for the user to enter a value, in another Sub I use the entered value to Call other Subs based on their input.

Am I close in my example? Thank you

Option Explicit

Sub MonthTest()
Dim strMonth As String

strMonth = InputBox("enter Area here")

Call Test2

End Sub

Sub Test2(strMonth As String)

Select Case strMonth
    Case Is = "82"
        Call Area82
    Case Is = "80"
        Call Area80
    
End Select
End Sub

Solution

  • Replace 'Call Test2withTest2 strMonth, there's no need to use Call`

    Variable declared in a sub/function stays in the sub/function itself only, since you have declare a parameter in Test2, you will need to provide the parameter everytime you call Test2 (unless its declare as Optional).