Private Sub Worksheet_Change(ByVal Target As Range)
Dim FiltCrit As String, myComboVal As String
Dim Rng As Range, Rng1 As Range, myCells As Range
Dim LR As Long, cNo As Long, x As Long
If Target.Cells.Count > 1 Or IsEmpty(Target) Then GoTo ExitSub
If Target.Address = "$L$4" Then
Application.EnableEvents = False
With ActiveSheet
.UsedRange.Offset(0, 68).ClearContents
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
If Not .AutoFilterMode Then
.Range("AA3:BI3").AutoFilter
End If
.Range(.Range("X4"), .Range("Y4").End(xlDown)).ClearContents
FiltCrit = .Range("L4").Value
With ActiveSheet.Shapes("Drop Down 3").ControlFormat
myComboVal = .List(.Value)
End With
Select Case myComboVal
Case "ZT/Feeder A1"
cNo = 2
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 29), .Cells(LR, 29)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca A1"
cNo = 2
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 30), .Cells(LR, 30)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder B1"
cNo = 10
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 37), .Cells(LR, 37)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca B1"
cNo = 10
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 38), .Cells(LR, 38)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder B2"
cNo = 13
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 40), .Cells(LR, 40)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca B2"
cNo = 13
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 41), .Cells(LR, 41)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder B3"
cNo = 16
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 43), .Cells(LR, 43)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca B3"
cNo = 13
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 44), .Cells(LR, 44)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder B4"
cNo = 19
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 46), .Cells(LR, 46)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca B4"
cNo = 19
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 47), .Cells(LR, 47)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder C1"
cNo = 27
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 54), .Cells(LR, 54)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca C1"
cNo = 27
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 55), .Cells(LR, 55)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder C2"
cNo = 30
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 57), .Cells(LR, 57)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca C2"
cNo = 30
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 58), .Cells(LR, 58)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Feeder C3"
cNo = 33
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 60), .Cells(LR, 60)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
Case "Arca C3"
cNo = 33
.Range("AA3:BI3").AutoFilter Field:=cNo, Criteria1:=FiltCrit
Set Rng = .AutoFilter.Range
x = Rng.Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
If x >= 1 Then
Set Rng = .Range(.Cells(4, 61), .Cells(LR, 61)).SpecialCells(xlCellTypeVisible)
Set Rng1 = .Range(.Cells(4, 27), .Cells(LR, 27)).SpecialCells(xlCellTypeVisible)
Set myCells = Union(Rng, Rng1)
Else
MsgBox "A Referência " & FiltCrit & " não existe em " & myComboVal
.ShowAllData
GoTo ExitSub
End If
myCells.Copy .Range("X4")
End Select
.ShowAllData
End With
End If
ExitSub: Application.EnableEvents = True: Application.CutCopyMode = False
ActiveSheet.Shapes("Drop Down 3").Select: Selection.Height = 24
Range("L4").Activate
End Sub
The other part is this one on module:
Bookmarks