Transfering a variable value from sub to another sub is possible ?

brkkrkmz112

New Member
Joined
Oct 24, 2016
Messages
43
Hi guys,

Im having trouble with a userform which contain textbox and combobox and I asked my question in a couple of part.

Firstly, ım trying to do when I activate the userform , it is supposed to ask me TimeSheet Num. That is so easy but the thing that ı get stuck on getting the TimeSheet num variable into Combobox code when the userform sub ends.


Second one ,

If the situation above seems like hard or impossible. With the code below, I can find the answer somehow . But every time I click the combobox button . It asks me the Timesheet num again and again. Is there a way to get rid of that

Actually if I can transfer the asking TimeSheetnum into Userform_initialize code , it would be perfect . Bu as ı said ı dont know how to transfer the value of a variable from a sub to another.
Thank you very much in advance.

Code:
Option Explicit

Private Sub CommandButton1_Click()
Dim kolon_no As Integer

Dim aralık As Range, k As Integer

Dim kolon As Range, columnnum As Integer

kolon_no = 0

Call setcolon(kolon_no)

Set aralık = ActiveSheet.Range("e3:aaa3")
Set kolon = aralık.Find(kolon_no)

columnnum = kolon.Column

For k = 7 To 28
Cells(k, columnnum) = Cells(k, columnnum) + controls("TextBox" & (k - 6)).Value
Next k

End Sub


Private Sub UserForm_Initialize()
Dim i As Integer
Dim k As Integer, m As Integer
For i = 7 To 28
m = i - 6
Me.controls("Label" & m).Caption = ActiveSheet.Range("A" & i).Value
Next i
End Sub


Function setcolon(z As Integer)

z = InputBox("TimeSheet Num", "TimeSheet Num ")

End Function
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you want a variable to be visible to all items, declare it as Public in a module.

I usually add a module called 'modPublic' purely for public variables.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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