Good afternoon or morning, my name is Daniel and I have just started using Excel VBA and I would like to know how to get all the values of a column based on a matching value through the filter function.
So far I have a form, please just pay attention to label4
(Name: LBL_CODIGO_SH), label5
(Name: LBL_CODIGO_SH) and combobox
(Name: ComboBox3).
My code is executed when clicking on the "Buscar" button
and it is the following:
Private Sub CommandButton4_Click()
Dim ws As Worksheet
Dim tabla As ListObject
Dim codigo As String
Set ws = Worksheets("Relacion")
Set tabla = ws.ListObjects("Tabla3")
codigo = Me.LBL_CODIGO_SH.Caption & "_" & Me.LBL_CODIGO_TH.Caption
Me.ComboBox3.List = WorksheetFunction.Filter( _
tabla.ListColumns(1).DataBodyRange, _
Evaluate(tabla.ListColumns(1).DataBodyRange.Value & "=" & codigo) _
)
End Sub
I run my program and it gives me error 13, I have a problem handling the "Filter" function of the spreadsheet, I think I'm skipping code. Could anyone help me? I would like to get the results in a combo box and also in an array variable.