PDA

View Full Version : Solved: Listbox Not Loading But should



coliervile
03-15-2008, 07:42 PM
I copied the following code from another userform listbox, but it's not loading as it should. The code is pretty basic... the userform is "frmAA", the listbox is "lstAA", and the worksheet is named "AA". I would appreciate your help.

Private Sub lstAA_Click()
Dim SourceRange As Excel.Range
Dim Val1 As String, Val2 As String, Val3 As String, Val4 As String, Val5 As String
If (lstAA.RowSource <> vbNullString) Then
'Get Range that the lstAA is bound to
Set SourceRange = Range(lstAA.RowSource)
Else
'Get first data row from worksheet "AA"
Set SourceRange = Range("'AA'!A2:E2")
Exit Sub
End If

Val1 = lstAA.Value
'Get the value of the second column
Val2 = SourceRange.Offset(lstAA.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Val3 = SourceRange.Offset(lstAA.ListIndex, 2).Resize(1, 1).Value
'Get the value of the fourth column
Val4 = SourceRange.Offset(lstAA.ListIndex, 3).Resize(1, 1).Value
'Get the value of the fifth column
Val5 = SourceRange.Offset(lstAA.ListIndex, 4).Resize(1, 1).Value

'Clean Up
Set SourceRange = Nothing
End Sub

coliervile
03-15-2008, 08:06 PM
Found what I was missing.