Simple UserForm TextBox Issue

oldcitycat

Board Regular
Joined
Sep 23, 2011
Messages
71
How do I carry theVname varaible from one sub to another?
The value thetextbox is avaiable within this sub but not If I try using it in the next sub

Code:
[FONT=Calibri]Public  Sub cbOk_Click()[/FONT]
[FONT=Calibri]Dim VName As String[/FONT]
[FONT=Calibri]VName =tbVesselName.Value[/FONT]
[FONT=Calibri]'MsgBox VName[/FONT]
[FONT=Calibri]Call ShowTXTBoxInfo[/FONT]
[FONT=Calibri]Unload Me[/FONT]
[FONT=Calibri]End Sub[/FONT]

[FONT=Calibri]Public Sub ShowTXTBoxVar()[/FONT]
[FONT=Calibri]MsgBox VName[/FONT]
[FONT=Calibri]End Sub[/FONT]
Thank you in advancefor any and all suggestion
OldCityCat
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,
there are few ways you can do this one is to pass your variable as an argument to your procedure.

Code:
Public Sub cbOk_Click()
    Dim VName As String
    VName = tbVesselName.Value
    'MsgBox VName
    Call ShowTXTBoxVar(VName)
    Unload Me
End Sub

Public Sub ShowTXTBoxVar(ByVal VName As String)
    MsgBox VName
End Sub

Dave
 
Upvote 0
Thanks,
What If I have 3 variables I need to use in another procedure?

OldCityCat

Just declare three arguments in your procedure & Pass values to it.

Sub Procname(arg As String, arg2 As Integer, arg3 As Boolean)
End Sub


They can, as shown in this example, be different data types & if required made optional (you are not required to pass a value in calling procedure)

Dave
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top