Hi Everyone,
I am writing a procedure which needs to capture the first and final week numbers of a range to be looked at by an analyst. ie the range week number 3 to 6. I have set up a userform with two comboboxes which are populated within the code with week numbers 1 to 52. I want to be able to pick a week number from each box and pass those numbers back to the main macro so it can load the appropriate range of files for processing. I have put msgboxes in the userform coding to check the week numbers are being picked up correctly, and they are. But when the userform is closed down (.hide) the main running macro does not know what week numbers were selected. Is there an easy way to make sure the values pass over?
This is the code in the main macro:
Sub Macro1()'
Dim firstweek As String
Dim Secondweek As String
UserForm1.Show
MsgBox "(Main Macro)First Week = " & firstweek
MsgBox "(Main Macro)Second Week = " & Secondweek
End Sub
This is the code in the Userform:
Private Sub CommandButton1_Click()
'Selected the Continue button
firstweek = ComboBox1.Value
Secondweek = ComboBox2.Value
UserForm1.Hide
MsgBox " first and second = " & firstweek & ", " & Secondweek
End Sub
Private Sub CommandButton2_Click()
'Selected the End button
MsgBox "End selected "
UserForm1.Hide
End
End Sub
Private Sub UserForm_Activate()
ComboBox1.List = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", _
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", _
"23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", _
"35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", _
"47", "48", "49", "50", "51", "52")
ComboBox2.List = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", _
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", _
"23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", _
"35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", _
"47", "48", "49", "50", "51", "52")
End Sub
Any suggestions will be gratefully accepted
Martin French
Bradford
UK