Formulario filtrar datos en listbox me cambia valores al ejecutar los filtros
publicado
Buenas tardes a los foreros y en especial a los maestros que tanto nos reportan con sus conocimientos a los iniciados, el problema que se me representa con el formulario es que al cargar los datos estos los importa correctamente es a la hora de usar el filtro tanto el Control como la Fecha, la fila de Objetivo% (es numérico) no me respeta los dos decimales sino que este los amplía hasta llegar a 8 decimales he buscado por el foro y no visto nada al respecto, os agradecería cómo solucionar dicho inconveniente Gracias por adelantado .......no puedo adjuntar el archivo me dice que es demasiado grande, adjunto macro por si sirve de algo.
Private Sub CommandButton3_Click()
Dim Columnas As Integer
Private Sub TextBox1_Change()
'Declaramos variables
Dim fin As Long, i As Long, n As Long
Dim sCadena_seccion As String
'Filtramos por sección
With Sheets("BD_CONTROL")
fin = Application.CountA(.Range("B:B"))
If TextBox1 = "" Then
Me.ListBox1.RowSource = ("B3:K") & Worksheets("BD_CONTROL").Range("B" & Rows.Count).End(xlUp).Row
Exit Sub
End If
Me.TextBox2 = Clear
'Me.TextBox3 = Clear
Me.ListBox1.RowSource = Clear
For i = 2 To fin
sCadena_matricula = .Cells(i, 2).Value
If UCase(sCadena_matricula) Like "*" & UCase(TextBox1.Value) & "*" Then
Me.ListBox1.AddItem
Me.ListBox1.List(n, 0) = .Cells(i, 2).Value
Me.ListBox1.List(n, 1) = .Cells(i, 3).Value
Me.ListBox1.List(n, 2) = .Cells(i, 4).Value
Me.ListBox1.List(n, 3) = .Cells(i, 5).Value
Me.ListBox1.List(n, 4) = .Cells(i, 6).Value
Me.ListBox1.List(n, 5) = .Cells(i, 7).Value
Me.ListBox1.List(n, 6) = .Cells(i, 8).Value
Me.ListBox1.List(n, 7) = .Cells(i, 9).Value
Me.ListBox1.List(n, 8 = .Cells(i, 10).Value 'objetivos%
Me.ListBox1.List(n, 9) = .Cells(i, 11).Value
n = n + 1
End If
Next
Me.ListBox1.ColumnWidths = "55pt;170pt;55pt;55pt;55pt;65pt;65pt;65pt;60pt;50pt"
End With
End Sub
Private Sub TextBox2_Change()
Dim fin As Long, i As Long, n As Long
Dim sCadena_seccion As String, sCadena_fecha As String
'Una vez filtrados los datos por matricula, filtramos por fecha
With Sheets("BD_CONTROL")
fin = Application.CountA(.Range("B:B"))
If TextBox2 = "" Then
Me.ListBox1.RowSource = ("B3:K") & Worksheets("BD_CONTROL").Range("B" & Rows.Count).End(xlUp).Row
Exit Sub
End If
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
For i = 2 To fin
sCadena_matricula = .Cells(i, 2).Value
sCadena_fecha = .Cells(i, 11).Value
If UCase(sCadena_matricula) Like "*" & UCase(TextBox1.Value) & "*" And _
UCase(sCadena_fecha) Like "*" & UCase(TextBox2.Value) & "*" Then
Me.ListBox1.AddItem
Me.ListBox1.List(n, 0) = .Cells(i, 2).Value
Me.ListBox1.List(n, 1) = .Cells(i, 3).Value
Me.ListBox1.List(n, 2) = .Cells(i, 4).Value
Me.ListBox1.List(n, 3) = .Cells(i, 5).Value
Me.ListBox1.List(n, 4) = .Cells(i, 6).Value
Me.ListBox1.List(n, 5) = .Cells(i, 7).Value
Me.ListBox1.List(n, 6) = .Cells(i, 8).Value
Me.ListBox1.List(n, 7) = .Cells(i, 9).Value
Me.ListBox1.List(n, 8 = .Cells(i, 10).Value 'objetivos%
Me.ListBox1.List(n, 9) = .Cells(i, 11).Value
n = n + 1
End If
Next
Me.ListBox1.ColumnWidths = "55pt;170pt;55pt;55pt;55pt;65pt;65pt;65pt;60pt;50pt"
End With
End Sub
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Buenas tardes a los foreros y en especial a los maestros que tanto nos reportan con sus conocimientos a los iniciados, el problema que se me representa con el formulario es que al cargar los datos estos los importa correctamente es a la hora de usar el filtro tanto el Control como la Fecha, la fila de Objetivo% (es numérico) no me respeta los dos decimales sino que este los amplía hasta llegar a 8 decimales he buscado por el foro y no visto nada al respecto, os agradecería cómo solucionar dicho inconveniente Gracias por adelantado .......no puedo adjuntar el archivo me dice que es demasiado grande, adjunto macro por si sirve de algo.
Private Sub CommandButton3_Click()
Dim Columnas As Integer
Columnas = Range("Tabla6").Columns.Count
Private Sub btnSalir_Click()
End
End Sub
Private Sub CommandButton3_Click()
Dim Columnas As Integer
Columnas = Range("Tabla6").Columns.Count
With Me.ListBox1
.ColumnCount = Columnas
.ColumnWidths = "55pt;160pt;55pt;55pt;55pt;65pt;65pt;65pt;60pt;50pt;0pt;0pt"
.ColumnHeads = True
.RowSource = "Tabla6"
End With
End Sub
Private Sub CommandButton4_Click()
Dim fila As Long, i As Long
fila = Hoja9.Range("B" & Rows.Count).End(xlUp).Row + 1
For i = 0 To ListBox1.ListCount - 1
Hoja9.Cells(fila, 2) = ListBox1.List(i, 0)
Hoja9.Cells(fila, 3) = ListBox1.List(i, 1)
Hoja9.Cells(fila, 5) = ListBox1.List(i, 2)
Hoja9.Cells(fila, 6) = ListBox1.List(i, 3)
Hoja9.Cells(fila, 7) = ListBox1.List(i, 4)
Hoja9.Cells(fila, ? = ListBox1.List(i, 5)
Hoja9.Cells(fila, 9) = ListBox1.List(i, 6)
Hoja9.Cells(fila, 10) = ListBox1.List(i, 7)
Hoja9.Cells(fila, 14) = ListBox1.List(i, ?
fila = fila + 1
Next i
End Sub
Private Sub CommandButton5_Click()
Dim fila As Long, i As Long
fila = Hoja10.Range("b" & Rows.Count).End(xlUp).Row
ListBox1.Clear
For i = 2 To fila
If CDate(Hoja10.Cells(i, 14)) >= CDate(f_inicial) And CDate(Hofa10.Cells(i, 14)) <= CDate(f_final) Then
Me.ListBox1
.AddItem
.List(.ListCount - 1, 0) = Hoja10.Cells(i, 2)
.List(.ListCount - 1, 2) = Hoja10.Cells(i, 0)
.List(.ListCount - 1, 3) = Hoja10.Cells(i, 1)
'.List(.ListCount - 1, 4) = Hoja10.Cells(i, 2)
.List(.ListCount - 1, 5) = Hoja10.Cells(i, 2)
.List(.ListCount - 1, 6) = Hoja10.Cells(i, 3)
.List(.ListCount - 1, 7) = Hoja10.Cells(i, 4)
.List(.ListCount - 1, ? = Hoja10.Cells(i, 5)
.List(.ListCount - 1, 9) = Hoja10.Cells(i, 6)
.List(.ListCount - 1, 10) = Hoja10.Cells(i, 7)
.List(.ListCount - 1, 14) = Hoja10.Cells(i, ?
End With
End If
Next i
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub TextBox1_Change()
'Declaramos variables
Dim fin As Long, i As Long, n As Long
Dim sCadena_seccion As String
'Filtramos por sección
With Sheets("BD_CONTROL")
fin = Application.CountA(.Range("B:B"))
If TextBox1 = "" Then
Me.ListBox1.RowSource = ("B3:K") & Worksheets("BD_CONTROL").Range("B" & Rows.Count).End(xlUp).Row
Exit Sub
End If
Me.TextBox2 = Clear
'Me.TextBox3 = Clear
Me.ListBox1.RowSource = Clear
For i = 2 To fin
sCadena_matricula = .Cells(i, 2).Value
If UCase(sCadena_matricula) Like "*" & UCase(TextBox1.Value) & "*" Then
Me.ListBox1.AddItem
Me.ListBox1.List(n, 0) = .Cells(i, 2).Value
Me.ListBox1.List(n, 1) = .Cells(i, 3).Value
Me.ListBox1.List(n, 2) = .Cells(i, 4).Value
Me.ListBox1.List(n, 3) = .Cells(i, 5).Value
Me.ListBox1.List(n, 4) = .Cells(i, 6).Value
Me.ListBox1.List(n, 5) = .Cells(i, 7).Value
Me.ListBox1.List(n, 6) = .Cells(i, 8).Value
Me.ListBox1.List(n, 7) = .Cells(i, 9).Value
Me.ListBox1.List(n, 8 = .Cells(i, 10).Value 'objetivos%
Me.ListBox1.List(n, 9) = .Cells(i, 11).Value
n = n + 1
End If
Next
Me.ListBox1.ColumnWidths = "55pt;170pt;55pt;55pt;55pt;65pt;65pt;65pt;60pt;50pt"
End With
End Sub
Private Sub TextBox2_Change()
Dim fin As Long, i As Long, n As Long
Dim sCadena_seccion As String, sCadena_fecha As String
'Una vez filtrados los datos por matricula, filtramos por fecha
With Sheets("BD_CONTROL")
fin = Application.CountA(.Range("B:B"))
If TextBox2 = "" Then
Me.ListBox1.RowSource = ("B3:K") & Worksheets("BD_CONTROL").Range("B" & Rows.Count).End(xlUp).Row
Exit Sub
End If
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
For i = 2 To fin
sCadena_matricula = .Cells(i, 2).Value
sCadena_fecha = .Cells(i, 11).Value
If UCase(sCadena_matricula) Like "*" & UCase(TextBox1.Value) & "*" And _
UCase(sCadena_fecha) Like "*" & UCase(TextBox2.Value) & "*" Then
Me.ListBox1.AddItem
Me.ListBox1.List(n, 0) = .Cells(i, 2).Value
Me.ListBox1.List(n, 1) = .Cells(i, 3).Value
Me.ListBox1.List(n, 2) = .Cells(i, 4).Value
Me.ListBox1.List(n, 3) = .Cells(i, 5).Value
Me.ListBox1.List(n, 4) = .Cells(i, 6).Value
Me.ListBox1.List(n, 5) = .Cells(i, 7).Value
Me.ListBox1.List(n, 6) = .Cells(i, 8).Value
Me.ListBox1.List(n, 7) = .Cells(i, 9).Value
Me.ListBox1.List(n, 8 = .Cells(i, 10).Value 'objetivos%
Me.ListBox1.List(n, 9) = .Cells(i, 11).Value
n = n + 1
End If
Next
Me.ListBox1.ColumnWidths = "55pt;170pt;55pt;55pt;55pt;65pt;65pt;65pt;60pt;50pt"
End With
End Sub