Macro de filtrado con fecha desde textbox.
Saludos.
Junto con saludar quisiera saber como puedo realizar el filtrado mediante macro de una fecha obtenida desde un textbox en un form. Te adjunto el código del modulo donde requiero que me haga el filtrado, es con excel 2007.
Sub conectar_con_la_base_de_datos()
Dim MyName As String
Dim Fecha As Long
Dim Equipo As String
MyName = UserForm9.Label3.Caption
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Select
Sheets(Sheets.Count).Name = MyName
Columns("G:H").Select
Selection.NumberFormat = "[$-F400]h:mm AM/PM"
Columns("I:I").Select
Selection.NumberFormat = "0.00"
Columns("C:C").Select
Selection.NumberFormat = "m/d/yyyy"
Range("A1") = UserForm9.Label3.Caption
Range("a1").Select
'Selection.NumberFormat = "m/d/yyyy"
Range("A2") = UserForm9.ComboBox1.Text
ruta = ThisWorkbook.Path
base_de_datos = "maquina1.mdb"
tabla = "Datos"
celda_inicial = "b6"
Application.ScreenUpdating = False
On Error Resume Next
Set Conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ruta & "\" & base_de_datos)
Sql = "Select * from " & tabla
rs.Open Sql, Conn, adOpenStatic, adLockOptimistic
registros_totales = rs.RecordCount
If Err > 0 Then
MsgBox (Chr(13) + " Lo sentimos, se han producido errores, " + _
Chr(13) + " y no se ha podido completar la operación. " + _
Chr(13) + Chr(13)), vbOKOnly, " Importación incorrecta"
Exit Sub
End If
Range(celda_inicial).Select
numero_de_campos = rs.Fields.Count
For i = 0 To numero_de_campos - 1
Selection.Font.Bold = True
ActiveCell = UCase(rs.Fields(i).Name)
ActiveCell.Offset(0, 1).Select
Next
If Rows.Count = 65536 Then
total_filas = 65536
máximo = total_filas - Range(celda_inicial).Row
Else
total_filas = 1000000
máximo = total_filas - Range(celda_inicial).Row
End If
Range(celda_inicial).Offset(1, 0).Select
contador = 1
Do While Not rs.EOF And contador <= máximo
For i = 0 To numero_de_campos - 1
ActiveCell = rs.Fields(i)
ActiveCell.Offset(0, 1).Select
Next
ActiveCell.Offset(0, -numero_de_campos).Select
If ActiveCell.Row < total_filas Then ActiveCell.Offset(1, 0).Select
rs.MoveNext
contador = contador + 1
Loop
Conn.Close
Set Conn = Nothing
Set rs = Nothing
Range("a3") = UserForm9.TextBox1.Text 'AQUÍ COMIENZA EL FILTRADO
Fecha = UserForm9.TextBox1.Text
Equipo = Range("a2")
With ActiveSheet
If .AutoFilterMode = True Then .AutoFilterMode = False
End With
ActiveSheet.Range("$B$6:$N$826").AutoFilter Field:=5, Criteria1:= _
Equipo
ActiveSheet.Range("$B$6:$N$826").AutoFilter Field:=2, Operator:= _
xlFilterValues, Criteria2:= _
Fecha
Application.ScreenUpdating = True
Unload UserForm9
End Sub
Esperando que puedas ayudarme y gracias por adelantado
Papelucho