Tengo un formulario donde quiero filtrar unos datos y que los traiga a un listbox pero cuando ejecuto la búsqueda me da el error siguiente: "Se ha producido el error 381 en tiempo de ejecución: Could not set the list property. Invalid property array index"
Describo el código que tengo por si me podéis ayudar a dar con el problema (lo tengo hecho en otra base de datos y me funciona perfectamente..... no entiendo porque en esta no...)
Private Sub cmbEncabezado_Change()
Me.lblFiltro = "Filtro por " & Me.cmbEncabezado.Value
End Sub
'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
Set h1 = Sheets("ENTIDADES")
Set h2 = Sheets("Temporal")
If Me.txtFiltro1.Value = "" Then
MsgBox "Debe introducir un criterio y un valor de búsqueda"
Exit Sub
If cmbEncabezado = "" Then
Exit Sub
End If
End If
For i = 2 To Range("a1").CurrentRegion.Rows.Count
If LCase(Cells(i, j)) Like "*" & LCase(txtFiltro1) & "*" Then
h1.Rows(i).Copy h2.Rows(n)
n = n + 1
End If
Next i
u = Range("A" & Rows.Count).End(xlUp).Row
If u = 1 Then
MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO"
Exit Sub
End If
ListBox1.RowSource = h2.Name & "!A2:T" & u
End Sub
'Dar formato al ListBox y traer los encabezados de la tabla
Private Sub UserForm_Initialize()
'
For i = 1 To 20
'Me.Controls("Label" & i) = Cells(1, i).Value
Next i
Buenas noches de nuevo!!
Tengo un formulario donde quiero filtrar unos datos y que los traiga a un listbox pero cuando ejecuto la búsqueda me da el error siguiente: "Se ha producido el error 381 en tiempo de ejecución: Could not set the list property. Invalid property array index"
Describo el código que tengo por si me podéis ayudar a dar con el problema (lo tengo hecho en otra base de datos y me funciona perfectamente..... no entiendo porque en esta no...)
Private Sub cmbEncabezado_Change()
Me.lblFiltro = "Filtro por " & Me.cmbEncabezado.Value
End Sub
'Mostrar resultado en ListBox
Private Sub CommandButton5_Click()
Set h1 = Sheets("ENTIDADES")
Set h2 = Sheets("Temporal")
If Me.txtFiltro1.Value = "" Then
MsgBox "Debe introducir un criterio y un valor de búsqueda"
Exit Sub
If cmbEncabezado = "" Then
Exit Sub
End If
End If
h2.Cells.Clear
ListBox1.RowSource = ""
h1.Rows(1).Copy h2.Rows(1)
j = cmbEncabezado.ListIndex + 1
n = 2
For i = 2 To Range("a1").CurrentRegion.Rows.Count
If LCase(Cells(i, j)) Like "*" & LCase(txtFiltro1) & "*" Then
h1.Rows(i).Copy h2.Rows(n)
n = n + 1
End If
Next i
u = Range("A" & Rows.Count).End(xlUp).Row
If u = 1 Then
MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO"
Exit Sub
End If
ListBox1.RowSource = h2.Name & "!A2:T" & u
End Sub
'Dar formato al ListBox y traer los encabezados de la tabla
Private Sub UserForm_Initialize()
'
For i = 1 To 20
'Me.Controls("Label" & i) = Cells(1, i).Value
Next i
[A1].Select
With Me
.ListBox1.ColumnHeads = True
.ListBox1.ColumnCount = 20
.ListBox1.ColumnWidths = "100 pt;55 pt;80 pt;75 pt;220 pt;50 pt;75 pt;75 pt;80 pt;200 pt;80 pt;90 pt; 80 pt; 75 pt; 80 pt; 70 pt; 60 pt; 60 pt; 60 pt; 60 pt"
.cmbEncabezado.List = Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value)
.cmbEncabezado.ListStyle = fmListStyleOption
End With
End Sub
'Cerrar formulario
Private Sub CommandButton2_Click()
Unload Me
End Sub
'Limpiar el Listbox
Private Sub CommandButton4_Click()
Me.ListBox1.RowSource = ""
End Sub
Muchas gracias por vuestra ayuda!!