How can I use my variable from sub procedure to add specific items for comboBox in userForm?
Sub procedure (Module code) -
Dim main As Integer
Public Sub dataValidation()
For i = 3 To 22
If Cells(i, 7).Value = "" Then
If Cells(i, 6).Value = "x" Then
main = 1
ElseIf Cells(i, 6).Value = "y" Then
main = 2
ElseIf Cells(i, 6).Value = "z" Then
main = 3
End If
form.Show
End If
Next
End Sub
Form initialization (Form code) -
Private Sub UserForm_Initialize()
cboSubtype.Value = "Select subtype"
if main = 1 then
cboSubtype.AddItem "a"
cboSubtype.AddItem "s"
elseif main = 2 then
cboSubtype.AddItem "d"
cboSubtype.AddItem "f"
elseif main = 3 then
cboSubtype.AddItem "g"
cboSubtype.AddItem "h"
End Sub
Subs to recognixe the samemain, so in your first line usePublic main As Integer. You should learn how to useSelect Caseinstaed of multipleIf>>Else.