¿Existe algún límite de filas en un listbox?
Tengo una base de datos de 15 columnas por 1000 filas. Un Combobox elige la columna dónde filtrar la información, un textbox permite realizar la búsqueda. Las coincidencias se muestran en un listbox. Mi duda es si hay alguna limitación en la búsqueda pues elijo la columna con un valor que identifico se que se encuentra en el valor 700 y el textbox me dice que el valor no se encuentra. ¿Qué puede ser?
2 Respuestas

Hice una prueba para cargar un millón de registros en un listbox y no tengo problemas.
Puedes poner aquí tu código para revisarlo.
También una imagen de como tienes tus datos, solamente una imagen con datos genéricos.
Y me explicas qué tienes en cada control y en dónde está el registro que debe encontrar.

Dante, muy buenas tardes! Gracias por la atención.
Al parecer no encuentra un dato de cualquier columna si existe una celda en blanco en la fila A, cualquier dato por debajo de este no es visto por el buscador. Pego un ejemplo
Lo cierto es que no debe haber un campo en blanco en la columna A pues es un numero univoco con distintas características descriptivas en las distintas columnas subsiguientes pudiendo haber campos en blanco en las columnas que siguen.
Dante te agradezco por despertar el interés por mejorar paso a paso.
Asunto solucionado.

No sé cómo está tu búsqueda, pero tal vez debas cambiar la forma de buscar, para que busque todos los registros de la hoja, sin importar si hay espacios en la columna A.

Dante, muy buenos días, la macro que estoy utilizando es:Gracias
Private Sub CommandButton5_Click() 'Act.Por.Dante Amor Set H1 = Sheets("Hoja1") Set h2 = Sheets("Temporal") ' If Me.txtFiltro1.Value = "" Then Exit Sub If cmbEncabezado = "" Then Exit Sub ' ListBox1.RowSource = "" 'EM: si limpias primero la hoja luego salta el error 1004 h2.Cells.Clear 'EM: Listbox1 se alimenta de h2. No debe limpiarse antes. 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 = h2.Range("A" & Rows.Count).End(xlUp).Row 'EM: buscar en h2 If u = 1 Then MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO" Exit Sub End If ListBox1.RowSource = h2.Name & "!A2:Z" & u End Sub
Gracias

Le hice algunas mejoras, prueba y me comentas.
Private Sub CommandButton5_Click() 'Por.Dante Amor Dim h1 As Worksheet, h2 As Worksheet, crit As Variant Dim j As Long, lr As Long, lc As Long, u As Long ' Set h1 = Sheets("Hoja1") Set h2 = Sheets("Temporal") ' h2.Cells.Clear If txtFiltro1 = "" Or cmbEncabezado = "" Then Exit Sub Application.ScreenUpdating = False ' If h1.AutoFilterMode Then h1.AutoFilterMode = False j = cmbEncabezado.ListIndex + 1 lr = h1.Cells(Rows.Count, j).End(3).Row lc = h1.Cells(1, Columns.Count).End(1).Column ' If IsNumeric(txtFiltro1) Then crit = txtFiltro1 Else crit = "=*" & txtFiltro1 & "*" h1.Range("A1", h1.Cells(lr, lc)).AutoFilter j, crit u = h1.Cells(Rows.Count, j).End(3).Row If u = 1 Then MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO" Else h1.AutoFilter.Range.EntireRow.Copy h2.Range("A1") ListBox1.RowSource = h2.Name & "!A2:Z" & u End If h1.ShowAllData Application.ScreenUpdating = True End Sub

Dante, gracias por el tiempo, hice algunas pruebas y rapidamente encuentra los valores aunque en la primer fila exista alguna celda en blanco. El asunto es que en la primer busqueda lo realiza correctamente como te mencione. El asunto es que si quiero realizar una nueva busqueda no encuentra nada, el listbox se queda en blanco.
¿qué sera?
Gracias por tu tiempo

Hice pruebas y cada búsqueda funciona bien.
Tienes otros códigos, pon aquí todo tu código aquí para revisarlo.

Aquí va:
'Option Explicit ' Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Const WS_MINIMIZEBOX As Long = &H20000 Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Const GWL_STYLE As Long = (-16) ' Private Sub UserForm_Initialize() Dim lngMyHandle As Long, lngCurrentStyle As Long, lngNewStyle As Long If Application.Version < 9 Then lngMyHandle = FindWindow("THUNDERXFRAME", Me.Caption) Else lngMyHandle = FindWindow("THUNDERDFRAME", Me.Caption) End If lngCurrentStyle = GetWindowLong(lngMyHandle, GWL_STYLE) lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX 'Or WS_MAXIMIZEBOX SetWindowLong lngMyHandle, GWL_STYLE, lngNewStyle 'Dar formato al ListBox y traer datos de la tabla Dim i As Long For i = 1 To 4 Me.Controls("Label" & i) = Cells(1, i).Value Next i 'For i = 1 To 15 'Me.Controls("Label" & i) = Cells(1, i).Value 'Next i ' [A1].Select With Me .ListBox1.ColumnHeads = False .ListBox1.ColumnCount = 15 .ListBox1.ColumnWidths = "80 pt;80 pt;190 pt; 10pt; 0pt;0 pt;0 pt; 0pt; 0pt;0 pt;0 pt; 0pt; 0pt;0 pt;0 pt; 0pt" .cmbEncabezado.List = Application.Transpose(ActiveCell.CurrentRegion.Resize(1).Value) .cmbEncabezado.ListStyle = fmListStyleOption End With End Sub 'Agregar material nuevo Private Sub CommandButton6_Click() frmAlta.Show End Sub 'Cerrar formulario Private Sub CommandButton2_Click() Unload frmMasinformacion Unload frmModificar Unload frmAlta Unload Me End Sub ' 'Abrir el formulario para modificar Private Sub CommandButton3_Click() If Me.ListBox1.ListIndex < 0 Then MsgBox "No se ha elegido ningún registro", vbExclamation, "" Else frmModificar.Show End If End Sub ' 'Eliminar el registro Private Sub CommandButton4_Click() Pregunta = MsgBox("Está seguro de eliminar el registro?", vbYesNo + vbQuestion, "") If Pregunta <> vbNo Then ActiveCell.EntireRow.Delete End If Call CommandButton5_Click End Sub ' 'Activar la celda del registro elegido Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Range("a2").Activate Cuenta = Me.ListBox1.ListCount Set Rango = Range("A1").CurrentRegion For i = 0 To Cuenta - 1 If Me.ListBox1.Selected(i) Then Valor = Me.ListBox1.List(i) Rango.Find(What:=Valor, LookAt:=xlWhole, After:=ActiveCell).Activate End If Next i frmMasinformacion.Show 'activa con un click el formulario con mas información frmMasinformacion.TextBox1 = ListBox1.Column(0) frmMasinformacion.TextBox1 = ListBox1.Column(0) frmMasinformacion.TextBox2 = ListBox1.Column(1) frmMasinformacion.TextBox3 = ListBox1.Column(2) frmMasinformacion.TextBox4 = ListBox1.Column(3) frmMasinformacion.TextBox5 = ListBox1.Column(4) frmMasinformacion.TextBox6 = ListBox1.Column(5) frmMasinformacion.TextBox7 = ListBox1.Column(6) frmMasinformacion.TextBox8 = ListBox1.Column(7) frmMasinformacion.TextBox9 = ListBox1.Column(8) frmMasinformacion.TextBox10 = ListBox1.Column(9) frmMasinformacion.TextBox11 = ListBox1.Column(10) frmMasinformacion.TextBox12 = ListBox1.Column(11) frmMasinformacion.TextBox13 = ListBox1.Column(14) frmMasinformacion.TextBox14 = ListBox1.Column(13) frmMasinformacion.TextBox15 = ListBox1.Column(12) 'copia valor de la primer columna Dim strList As String 'Dim i As Integer For i = 0 To Me.ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) = True Then If Len(Trim(Me.ListBox1.List(i))) > 0 Then ' blank values excluded here strList = strList & Trim(Me.ListBox1.List(i)) & " " & vbNewLine ' End If End If Next i Dim MyData As DataObject Set MyData = New DataObject MyData.Clear MyData.SetText Trim(strList) MyData.PutInClipboard End Sub Private Sub CommandButton5_Click() 'Por.Dante Amor Dim h1 As Worksheet, h2 As Worksheet, crit As Variant Dim j As Long, lr As Long, lc As Long, u As Long ' Set h1 = Sheets("Hoja1") Set h2 = Sheets("Temporal") ' h2.Cells.Clear If txtFiltro1 = "" Or cmbEncabezado = "" Then Exit Sub Application.ScreenUpdating = False ' If h1.AutoFilterMode Then h1.AutoFilterMode = False j = cmbEncabezado.ListIndex + 1 lr = h1.Cells(Rows.Count, j).End(3).Row lc = h1.Cells(1, Columns.Count).End(1).Column ' If IsNumeric(txtFiltro1) Then crit = txtFiltro1 Else crit = "=*" & txtFiltro1 & "*" h1.Range("A1", h1.Cells(lr, lc)).AutoFilter j, crit u = h1.Cells(Rows.Count, j).End(3).Row If u = 1 Then MsgBox "No existen registros con ese filtro", vbExclamation, "FILTRO" Else h1.AutoFilter.Range.EntireRow.Copy h2.Range("A1") ListBox1.RowSource = h2.Name & "!A2:Z" & u End If h1.ShowAllData Application.ScreenUpdating = True End Sub 'Cambia el TextBox con cada cambio en el Combo ' Private Sub cmbEncabezado_Change() Me.lblFiltro = "Filtro por " & Me.cmbEncabezado.Value txtFiltro1.Value = "" End Sub
- Compartir respuesta
