Llenar la columna 11 de un ListBox.
Sé que por defecto un ListBox admite un máximo de 10 columnas. Pero también sé que se le pueden añadir más de 10 por código.
El caso es que para 10 columnas me funciona más que correctamente -por lo que no quisiera cambiarlo-, el siguiente código generador de un ListBox, que, por otro lado, utilizo hasta para 7 botones de comando generadores del mismo TestBox, aunque con contenido potencialmente diferente:
Dim HojaBase As Worksheet Dim Rango As Range Dim Columna As Integer Dim i As Integer Dim Filas As Integer ' LIMPIO LOS OTROS FILTROS DE BÚSQUEDA Y EL PROPIO LISTBOX Me.TxtBuscar_Fch = Null Me.txtBuscar_Nom = Null Me.txtBuscar_Nif = Null Me.txtBuscar_Sol = Null Me.txtBuscar_Med = Null Me.txtBuscar_Obs = Null Me.Txt_BusquedaGlobal = Null Me.txtBuscar_Cod.SetFocus Me.ListBox1.Clear On Error GoTo ManejadorErrores Set HojaBase = ThisWorkbook.Sheets("MIS_EXPEDIENTES") Set Rango = HojaBase.Range("A1").CurrentRegion If Me.txtBuscar_Cod.Value = "" Then Exit Sub Me.ListBox1.Clear Columna = 1 Filas = Rango.Rows.Count With Me.ListBox1 For i = 2 To Filas If VBA.LCase(HojaBase.Cells(i, Columna).Value) Like "*" & VBA.LCase(Me.txtBuscar_Cod.Value) & "*" Then .AddItem HojaBase.Cells(i, 1).Value .List(Me.ListBox1.ListCount - 1, 1) = HojaBase.Cells(i, 3).Value .List(Me.ListBox1.ListCount - 1, 2) = HojaBase.Cells(i, 4).Value .List(Me.ListBox1.ListCount - 1, 3) = HojaBase.Cells(i, 5).Value .List(Me.ListBox1.ListCount - 1, 4) = HojaBase.Cells(i, 7).Value If HojaBase.Cells(i, 12) = "Sí" Then Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = "Sí" ElseIf HojaBase.Cells(i, 12) = "No" Then Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = "No" End If If HojaBase.Cells(i, 13) = "Sí" Then Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = "Sí" ElseIf HojaBase.Cells(i, 13) = "No" Then Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = "No" End If .List(Me.ListBox1.ListCount - 1, 7) = HojaBase.Cells(i, 34).Value .List(Me.ListBox1.ListCount - 1, 8) = HojaBase.Cells(i, 58).Value .List(Me.ListBox1.ListCount - 1, 9) = HojaBase.Cells(i, 59).Value '''''' .List(Me.ListBox1.ListCount - 1, 10) = HojaBase.Cells(i, 60).Value ' ES LA COLUMNA 11 DEL LISTBOX -QUE POR DEFECTO SOLO ADMITE 10-. End If Next i End With Me.Registros.Value = Me.ListBox1.ListCount Exit Sub ManejadorErrores: MsgBox "Ha ocurrido un error: " & Err.Description, vbExclamation, "EXPEDIENTES"
Lógicamente al 'descomentar' la escritura prevista en el código anterior para la columna 11 del ListBox, en tanto en cuanto no haya definido antes un 'Rango' superior a 10 columnas, error... Pero no sé cómo hacerlo...
¿Alguien me puede echar una mano...?
1 respuesta
Respuesta de Dante Amor
1