M
macroplay
I have a macro with 2 listboxes that I want to use for selecting values from
2 lists. The main macro shows both lists sequentially and then uses the 2
selected values to process data. Unfortunately when certain values in the
first list are selected, the 2nd list box is not displayed but the main macro
code continues as if a val;ue from the 2nd list had been selected.
Below is the code in which the same form is used for both lists. I tried
using two separate forms but that didn't help. If I uncomment the msgbox code
in the init routine, the lists work properly.
Column A has values a,b,c,d,e,blank and column b has values 1,2,3, blank
======================
Private Sub ListBox1_Click()
poolName = ListBox1.Value
Unload Me
End Sub
Private Sub userform_initialize()
'MsgBox "form 1 init"
Windows("InvoiceMacro.xls").Activate
Sheets("Lists").Select
If listnum = 1 Then Range("a1").Select Else Range("b1").Select
Do Until ActiveCell.Value = ""
ListBox1.AddItem (ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Private Sub UserForm_Click()
End Sub
++++ main macro
Sub doboth()
listnum = 1
frmListbox1.Show
listnum = 2
frmListbox1.Show
End Sub
2 lists. The main macro shows both lists sequentially and then uses the 2
selected values to process data. Unfortunately when certain values in the
first list are selected, the 2nd list box is not displayed but the main macro
code continues as if a val;ue from the 2nd list had been selected.
Below is the code in which the same form is used for both lists. I tried
using two separate forms but that didn't help. If I uncomment the msgbox code
in the init routine, the lists work properly.
Column A has values a,b,c,d,e,blank and column b has values 1,2,3, blank
======================
Private Sub ListBox1_Click()
poolName = ListBox1.Value
Unload Me
End Sub
Private Sub userform_initialize()
'MsgBox "form 1 init"
Windows("InvoiceMacro.xls").Activate
Sheets("Lists").Select
If listnum = 1 Then Range("a1").Select Else Range("b1").Select
Do Until ActiveCell.Value = ""
ListBox1.AddItem (ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Private Sub UserForm_Click()
End Sub
++++ main macro
Sub doboth()
listnum = 1
frmListbox1.Show
listnum = 2
frmListbox1.Show
End Sub