Andy I modified the code which looks correct need a little help connecting the drop down box to the list box. I added an additional worksheet called reports
Private Sub CmdReportsClose_Click()
Unload Me
End Sub
Private Sub Cmp_list_Change()
Dim SourceRange As Excel.Range
Dim Col1 As String, Col2 As String, Col3 As String
If (Cmp_List.RowSource <> vbNullString) Then
'Get Range that the List Box is bound to
Set SourceRange = Range(Cmp_List.RowSource)
Else
'Get first row of data
Set SourceRange = Range("Reports!G2:I2")
Exit Sub
End If
Col1 = Cmp_List.Value
'Get the value of the second column
Col2 = SourceRange.Offset(Cmp_List.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Col3 = SourceRange.Offset(Cmp_List.ListIndex, 2).Resize(1, 1).Value
'Clean Up
Set SourceRange = Nothing
End Sub
Private Sub Open_Cmb_Click()
'This changes the value of the comboBox to year
Open_Cmb.Value = Format(Open_Cmb.Value, "yyyy")
End Sub
Private Sub Open_List_Change()
Dim SourceRange As Excel.Range
Dim Col1 As String, Col2 As String, Col3 As String
If (Open_List.RowSource <> vbNullString) Then
'Get Range that the List Box is bound to
Set SourceRange = Range(Open_List.RowSource)
Else
'Get first row of data
Set SourceRange = Range("Reports!B2:D2")
Exit Sub
End If
Col1 = Open_List.Value
'Get the value of the second column
Col2 = SourceRange.Offset(Open_List.ListIndex, 1).Resize(1, 1).Value
'Get the value of the third column
Col3 = SourceRange.Offset(Open_List.ListIndex, 2).Resize(1, 1).Value
'Clean Up
Set SourceRange = Nothing
End Sub
Private Sub UserForm_Initialize()
'Set properties of the list box
With Me.Cmp_List
.BoundColumn = 1
.ColumnCount = 3
.RowSource = "Reports!G2:I2"
With Me.Open_List
.BoundColumn = 1
.ColumnCount = 3
.RowSource = "Reports!B2:D2"
End With
End With
End Sub
Bookmarks