View Single Post
  #1   Report Post  
r1024768 r1024768 is offline
Junior Member
 
Posts: 7
Default Excel vba UserForm Lists not registering default values?

Hi,

I have 3 lists on my UserForm, all initiated as follows:

List.Clear
With List
.addItem "a"
.addItem "b"
etc.
End With

At the very end, I have:
List1.Value = "a"
List2.Value = "b"
List3.Value = "c"

Msgbox List1.Value & List2.Value & List3.Value

Currently List2.Value returns a blank - I've also had it switch to List1 being blank between loads (no code touched, just saving, exporting to test the form, and exiting before going back in)
EDIT: After running it repeatedly without exiting, I find that it just seems to randomize between which ones show up at all even without exiting...

However, it registers the default value of the list selection - whichever value I set those lists to is what the list starts off having selected. It just doesn't seem to want to show the value in the Msgbox, and subsequently, anything I try to use that initial value in.

Any clue what's going on?

Exact Code:
Code:
Private Sub UserForm_Initialize()

    ListBox1.Clear
    ListBox2.Clear
    ListBox3.Clear

With ListBox1
    .AddItem "a"
    .AddItem "b"
    .AddItem "c"
End With

With ListBox2
    .AddItem "a"
    .AddItem "b"
    .AddItem "c"
End With

With ListBox3
    .AddItem "a"
    .AddItem "b"
    .AddItem "c"
End With

ListBox1.Value = "b"
ListBox2.Value = "c"
ListBox3.Value = "a"

MsgBox ListBox1.Value & ListBox2.Value & ListBox3.Value

End Sub

Last edited by r1024768 : April 2nd 13 at 11:58 PM Reason: Added code + update