passing variables from userform to module

bradystreet212

New Member
Joined
Feb 29, 2012
Messages
5
I've been working on a userform so I can input multiple values all at once instead of the annoying input box that pops up a hundred times a day. I'm not sure whats needs done to transfer the input data into my module so that my macro can recognize what the user has put in the text boxes.

Module:

sub test()
load userform
userform.show
end sub

sub MainSub(byref c1 as string, byref c2 as integer)
dim CoFr as string, CoTo as integer

CoFr = c1
CoTo = c2
end sub


UserForm:
public Var1 as string, Var2 as integer
sub CmdOK()
Var1 = userform.textbox1.text
Var2 = userform.textbox2.value

Call MainSub(Var1, Var2)

unload userform
end sub

this is how I'm approaching it but I don't think its right? is there another step or a different way to approach this? declaring variables a different way, adding another sub add() or something.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,225,611
Messages
6,185,996
Members
453,334
Latest member
Prakash Jha

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