Macro VBA Excel para buscar en 3 hojas según condición
Esta macro
Private Sub cmbBusque_Click()
'Por.Dante Amor
'Filtrar por fecha
Dim U As Double, i As Double
Dim h1 As Object, h2 As Object
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set h1 = Sheets("Productos")
Set h2 = Sheets("Filtro")
h2.Cells.Clear
'
If DTPicker1 > DTPicker2 Then
MsgBox "La fecha inicial no puede ser superior a la final", vbExclamation, "REVISAR FECHAS"
Application.ScreenUpdating = True
Exit Sub
End If
'
If h1.AutoFilterMode Then h1.AutoFilterMode = False
U = h1.Range("E" & Rows.Count).End(xlUp).Row
h1.Range("A1:g" & U).AutoFilter
h1.Range("A1:g" & U).AutoFilter Field:=5, Criteria1:=">=" & Format(DTPicker1, "mm/dd/yyyy"), _
Operator:=xlAnd, Criteria2:="<=" & Format(DTPicker2, "mm/dd/yyyy")
If h1.Range("E" & Rows.Count).End(xlUp).Row = 1 Then
MsgBox "No existen registros", vbExclamation, "REVISAR FECHAS"
If h1.AutoFilterMode Then h1.AutoFilterMode = False
Application.ScreenUpdating = True
Exit Sub
End If
'
h1.Range("A1:g" & U).Copy h2.[A1]
ListBox1.RowSource = h2.Name & "!A2:g" & h2.Range("g" & Rows.Count).End(xlUp).Row
If h1.AutoFilterMode Then h1.AutoFilterMode = False
''' Cuenta y muestra cantidad de items en el ListBox
txtExistencia.Text = ListBox1.ListCount
'''
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Subejecuta una busqueda(filtra) entre fechas dentro de una hoja (Productos); Fecha inicial y fecha final.
Como se ve en el formulario, le agregue 3 OptionBotton con nombre de hoja respectiva
Se agradece la buena voluntad en darme esa mano de ayuda, en editar la macro para que me busque en la hoja según la condición true del OptionBotton.

Respuesta de Adriel Ortiz Mangia
1

