title: Listbox not returning data correctly in excel vba
body: <p>I have a listbox in a userform with 13 options, similar to:
  <a href="https://i.stack.imgur.com/0ctRx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0ctRx.png" alt="This is for demonstration purposes only"></a></p>
  
  <p>What I am tying to get it to do is that when an item is chosen, it returns a specific result.  By this I mean:  chicken leg as 'a',
  nugget = 'b',
  burger = 'c', etc...</p>
  
  <p>This is the code I've come up with:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim lItem As Long
      For lItem = 0 To ListBox1.ListCount - 1
      If ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "a"
      ElseIf ListBox1.Selected(lItem) = 1 Then
          Worksheets(3).Range("E1").Value = "b"
      ElseIf ListBox1.Selected(lItem) = 2 Then
          Worksheets(3).Range("E1").Value = "c"
      ElseIf ListBox1.Selected(lItem) = 3 Then
          Worksheets(3).Range("E1").Value = "d"
      ElseIf ListBox1.Selected(lItem) = 4 Then
          Worksheets(3).Range("E1").Value = "e"
      ElseIf ListBox1.Selected(lItem) = 5 Then
          Worksheets(3).Range("E1").Value = "f"
      ElseIf ListBox1.Selected(lItem) = 6 Then
          Worksheets(3).Range("E1").Value = "fs"
      ElseIf ListBox1.Selected(lItem) = 7 Then
          Worksheets(3).Range("E1").Value = "g"
      ElseIf ListBox1.Selected(lItem) = 8 Then
          Worksheets(3).Range("E1").Value = "gs" 'its not a straight sequence as such
      ElseIf ListBox1.Selected(lItem) = 9 Then
          Worksheets(3).Range("E1").Value = "h"
      ElseIf ListBox1.Selected(lItem) = 10 Then
          Worksheets(3).Range("E1").Value = "i"
      ElseIf ListBox1.Selected(lItem) = 11 Then
          Worksheets(3).Range("E1").Value = "j"
      ElseIf ListBox1.Selected(lItem) = 12 Then
          Worksheets(3).Range("E1").Value = "js"
      '...................................................
      'from here on it is for when two items are selected'
      ''''''''''''''''''''''''''''''''''''''''''''''''''''
      ElseIf ListBox1.Selected(lItem) = 1 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ab"
      ElseIf ListBox1.Selected(lItem) = 2 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ac"
      ElseIf ListBox1.Selected(lItem) = 3 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ad"
      ElseIf ListBox1.Selected(lItem) = 4 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ae"
      ElseIf ListBox1.Selected(lItem) = 5 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "af"
      ElseIf ListBox1.Selected(lItem) = 6 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "afs"
      ElseIf ListBox1.Selected(lItem) = 7 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ag"
      ElseIf ListBox1.Selected(lItem) = 8 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ags"
      ElseIf ListBox1.Selected(lItem) = 9 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ah"
      ElseIf ListBox1.Selected(lItem) = 10 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ai"
      ElseIf ListBox1.Selected(lItem) = 11 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "aj"
      ElseIf ListBox1.Selected(lItem) = 12 And ListBox1.Selected(lItem) = 0 Then
          Worksheets(3).Range("E1").Value = "ajs"
      Else
      '...................................................
      ' more code for many more selections               '
      ' i stopped when i realised it wasn't quite working'
      ''''''''''''''''''''''''''''''''''''''''''''''''''''
      End If
  Next
  End Sub
  </code></pre>
  
  <p>I hope it is clear what I am trying to achieve.</p>
  
  <p>The problem is that, whatever is selected, only returns 'a', no matter how many are selected or whether 'chicken leg' is even selected.  What is missing?</p>
  
  <p>I suspect that it's something fairly fundamental, as I am new to vba :)</p>
  
  <p>Another way I have also tried is:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
      If ListBox1.Value = "chicken leg" Then
          Worksheets(3).Range("E1").Value = "a"
      ElseIf ListBox1.Value = "nugget" Then
          Worksheets(3).Range("E1").Value = "b"
      ElseIf ListBox1.Value = "burger" Then
          Worksheets(3).Range("E1").Value = "c"
      ElseIf ListBox1.Value = "sandwich" Then
          Worksheets(3).Range("E1").Value = "d"
      Else
  End if
  End sub
  </code></pre>
  
  <p>But that didn't work at all...</p>
  
  <p>Can someone please help??</p>
  
  <p>Thanks</p>