This code attempts to take what the user selects from ComboBox1 and use that as the criteria to search for a matching record(s) in the table named "Emp_Table". I have attempted to make the list of records returned dynamic so that it only refers to the filtered list, rather than all items. I get a Run Time Error 13, Type Mismatch which errors on the .RowSource = MyRange line. I get multiple errors of different types every time I change something and I don't understand why.
With ListBox2 it should then populate a list box on the same form with the titles of the columns (I only need the data in A & B at the moment) and the relevant data in the rows underneath. I'm stuck and going around in circles, so if you can run this through your VB and provide me with a solution I would appreciate it very much! Thank you.
Private Sub ComboBox1_Change()
Dim LastRow
Dim MyRange As Range
Set MyRange = Range("A1", Range("B2").End(xlDown))
Set sh = ThisWorkbook.Sheets("EMPMaster")
ActiveSheet.ListObjects("Emp_Table").Range.AutoFilter Field:=3, Criteria1:=ComboBox1.value
ListBox2.RowSource = ""
With Worksheets("EMPMaster")
LastRow = .Range("A1").CurrentRegion.Rows.Count
For Each cell In .Range("A1:b" & LastRow).SpecialCells(12)
Next
End With
With Me.ListBox2
.ColumnHeads = True
.ColumnCount = 2
.ColumnWidths = "70,120"
.RowSource = MyRange
End With
End Sub
With ListBox2 it should then populate a list box on the same form with the titles of the columns (I only need the data in A & B at the moment) and the relevant data in the rows underneath. I'm stuck and going around in circles, so if you can run this through your VB and provide me with a solution I would appreciate it very much! Thank you.
Private Sub ComboBox1_Change()
Dim LastRow
Dim MyRange As Range
Set MyRange = Range("A1", Range("B2").End(xlDown))
Set sh = ThisWorkbook.Sheets("EMPMaster")
ActiveSheet.ListObjects("Emp_Table").Range.AutoFilter Field:=3, Criteria1:=ComboBox1.value
ListBox2.RowSource = ""
With Worksheets("EMPMaster")
LastRow = .Range("A1").CurrentRegion.Rows.Count
For Each cell In .Range("A1:b" & LastRow).SpecialCells(12)
Next
End With
With Me.ListBox2
.ColumnHeads = True
.ColumnCount = 2
.ColumnWidths = "70,120"
.RowSource = MyRange
End With
End Sub