Macro VBA filtra por variables definidas copia y pega el resultado

Estoy armando una rutina en VBA para filtrar por unas variables definidas (3- una a la vez), ir a la hoja donde esta la información, copiar el resultado y pegarlo en otra hoja, tengo un problema ya que me está haciendo los tres filtros al tiempo con lo cuál sólo me queda el encabezado para copiar y pegar, no se que estoy haciendo mal, soy inexperto. Copio la rutina.

Sub Filtro()
Dim gerencia As String
Dim zona As String
Dim gerente As String
Dim objetivo As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("BASE").Visible = True
Application.EnableEvents = True
Sheets("BASE").Select
Range("A1").Select
ActiveSheet.AutoFilterMode = False
gerencia = Sheets("seguimiento").Cells(2, 7)
zona = Sheets("seguimiento").Cells(4, 7)
gerente = Sheets("seguimiento").Cells(6, 7)
Sheets("SEGUIMIENTO").Select
If (Cells(7, 7)) = "DIV" Then
objetivo = gerencia
If (Cells(7, 7)) = "ZON" Then
objetivo = zona
If (Cells(7, 7)) = "GTE" Then
objetivo = gerente
End If
End If
End If
Sheets("BASE").Select
Range("A1").Select
If objetivo = gerencia Then
Selection.AutoFilter field:=13, Criteria1:=gerencia
If objetivo = zona Then
Selection.AutoFilter field:=12, Criteria1:=zona
If objetivo = gerente Then
Selection.AutoFilter field:=3, Criteria1:=gerente
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Sheets("CONSULTA").Select
Range("A1").PasteSpecial Paste:=xlPasteValues, operation:=xlNone, skipblanks:=False
Sheets("CONSULTA").Select
Range("A1").Select
'Sheets("BASE").Visible = False
Application.EnableEvents = True
End If
End If
End If
End Sub

1 Respuesta

Respuesta

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas