Excel - Listas desplegables con filtros

 
Vista:

Listas desplegables con filtros

Publicado por ivan cummings (1 intervención) el 28/11/2013 16:37:22
Buen Día,

Estoy ingresando al mundo de los macros y me ha tocado un proyecto algo complejo para mis conocimientos. Necesito hacer unas listas desplegables que cuando elija la lista1 el valor escogido filtre en la lista 2

tengo un código que hace lo que necesito, pero solo lo hace para la fila 9 y lo necesito para todas las filas. Estaría eternamente agradecido si me pudieran ayudar, abajo les dejo el código que tengo

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A9:C9")) Is Nothing Then
With Target
If .Rows.Count > 1 Then Exit Sub
On Error Resume Next
Application.ScreenUpdating = False
Select Case .Offset(-1)
Case Is = "Cliente":
Columns("X:Z").Delete
Hoja3.Range("A:A").AdvancedFilter 2, , Range("Z1"), 1
uf = Range("Z" & Rows.Count).End(xlUp).Row
Columns("Z").Sort Range("Z1"), xlAscending, Header:=xlYes
With .Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=Z2:Z" & uf
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = False
.ShowError = False
End With
Columns("X:Z").Hidden = True
Case Is = "Proyecto":
Columns("X:Z").Delete
pp = WorksheetFunction.Match(Range("A9"), Hoja3.Columns("A"), 0)
cpp = WorksheetFunction.CountIf(Hoja3.Columns("A"), Range("A9"))
With Hoja3
If cpp > 1 Then
.Range(.Cells(pp, "A"), .Cells(pp + cpp - 1, "B")).AdvancedFilter 2, , Range("Y1"), 1
Else
Range("Z2") = .Cells(pp, "B")
End If
End With
Hoja3.Range("A1:B1").Copy Range("Y1")
Range("Y1").CurrentRegion.Sort Range("Z1"), xlAscending, Header:=xlYes
uf = Range("Z" & Rows.Count).End(xlUp).Row
With .Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=Z2:Z" & uf
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = False
.ShowError = False
End With
Columns("X:Z").Hidden = True
Case Is = "Orden":
Columns("X:Z").Delete
With Hoja3.Range("A1").CurrentRegion
.AutoFilter 1, Range("A9").Text
.AutoFilter 2, Range("B9").Text
.Copy Range("X1")
.AutoFilter
End With
Range("X1").CurrentRegion.Sort Range("Z1"), xlAscending, Header:=xlYes
uf = Range("Z" & Rows.Count).End(xlUp).Row
With .Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=Z2:Z" & uf
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = False
.ShowError = False
End With
Columns("X:Z").Hidden = True
End Select
On Error GoTo 0
Application.ScreenUpdating = True
'SendKeys "%{down}"
End With
End If
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder