Ayuda en código de filtro
Buen Día
Espero me puedan ayudar para que me de cualquiera de las dos opciones en la parte de if existe: cuando encuentra los datos debe filtrarlos y preguntar si deseo imprimir y si no encuentra datos me debe decir "Dato no encontrado" y generar la opción de nueva búsqueda. Díganme que debo cambiarle. De antemano muchas gracias (y) he aquí el código.
Option Explicit
Sub ejemplo()
Sheets("ENERO-AGOSTO 2011 POR TIENDAS").Select Range("E1").Select
Dim existe As Boolean
Dim d As String
d = InputBox("BUSCAR:", "buscador")
If Len(d) = 0 Then Exit Sub
filtrar (d)
If existe = False Then
MsgBox d & " Dato no encontrado ", vbCritical
Exit Sub ' si el dato no existe en rango sale del sub
End If d = MsgBox("Desea imprimir esta información?", vbYesNo + vbInformation)
If d = 6 Then imprime
End Sub
Sub filtrar(dato As String)
Dim existe As Boolean
Dim n As Long
'verifica que existen datos en la hoja
n = Application.WorksheetFunction.CountA(Range("E:E"))
If n = 0 Then Exit Sub
'verifica que el dato ingresado existe en el rango antes de filtrar
If Application.WorksheetFunction.CountIf(Range("E:E"), dato) = 0 Then
existe = False
Exit Sub
Else
existe = True
End If
'ejecuta filtro
[A1].Select
Selection.AutoFilter
ActiveSheet.Range("$A$1" & ":" & "$U$" & n).AutoFilter Field:=5, Criteria1:=dato
End Sub
Sub imprime()
'imprime area seleccionada, previamente filtrada
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
Range("A1").Select
End Sub
Espero me puedan ayudar para que me de cualquiera de las dos opciones en la parte de if existe: cuando encuentra los datos debe filtrarlos y preguntar si deseo imprimir y si no encuentra datos me debe decir "Dato no encontrado" y generar la opción de nueva búsqueda. Díganme que debo cambiarle. De antemano muchas gracias (y) he aquí el código.
Option Explicit
Sub ejemplo()
Sheets("ENERO-AGOSTO 2011 POR TIENDAS").Select Range("E1").Select
Dim existe As Boolean
Dim d As String
d = InputBox("BUSCAR:", "buscador")
If Len(d) = 0 Then Exit Sub
filtrar (d)
If existe = False Then
MsgBox d & " Dato no encontrado ", vbCritical
Exit Sub ' si el dato no existe en rango sale del sub
End If d = MsgBox("Desea imprimir esta información?", vbYesNo + vbInformation)
If d = 6 Then imprime
End Sub
Sub filtrar(dato As String)
Dim existe As Boolean
Dim n As Long
'verifica que existen datos en la hoja
n = Application.WorksheetFunction.CountA(Range("E:E"))
If n = 0 Then Exit Sub
'verifica que el dato ingresado existe en el rango antes de filtrar
If Application.WorksheetFunction.CountIf(Range("E:E"), dato) = 0 Then
existe = False
Exit Sub
Else
existe = True
End If
'ejecuta filtro
[A1].Select
Selection.AutoFilter
ActiveSheet.Range("$A$1" & ":" & "$U$" & n).AutoFilter Field:=5, Criteria1:=dato
End Sub
Sub imprime()
'imprime area seleccionada, previamente filtrada
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
Range("A1").Select
End Sub
1 respuesta
Respuesta de calvuch
1