Dunk4Divin
New Member
- Joined
- Aug 21, 2019
- Messages
- 17
- Office Version
- 365
- Platform
- Windows
Hi All
I have a problem with the code below which as it stands, it works. But if you read through you will see that the last section with arrays for the selected criteria doesn't include all the possible variables i.e. it is possible to select up to 12 engineers but if include all 12 references into the array it fails because there is only 7 engineers selected for my example leaving 5 blank cells, the same issue occurs with the second and third arrays. How do I get the arrays to "ignore" the blank cells?
Any help will be gratefully received, thanks in advance
I have a problem with the code below which as it stands, it works. But if you read through you will see that the last section with arrays for the selected criteria doesn't include all the possible variables i.e. it is possible to select up to 12 engineers but if include all 12 references into the array it fails because there is only 7 engineers selected for my example leaving 5 blank cells, the same issue occurs with the second and third arrays. How do I get the arrays to "ignore" the blank cells?
Any help will be gratefully received, thanks in advance
VBA Code:
Sub FilterData()
On Error GoTo EH:
ActiveSheet.ShowAllData
EH:
Dim Engineer1, Engineer2, Engineer3, Engineer4, Engineer5, Engineer6, Engineer7, Engineer8, Engineer9, Engineer10, Engineer11, Engineer12 As Range
With Worksheets("Team Sheet")
Set Engineer1 = .Range("A4")
Set Engineer2 = .Range("A5")
Set Engineer3 = .Range("A6")
Set Engineer4 = .Range("A7")
Set Engineer5 = .Range("A8")
Set Engineer6 = .Range("A9")
Set Engineer7 = .Range("A10")
Set Engineer8 = .Range("A11")
Set Engineer9 = .Range("A12")
Set Engineer10 = .Range("A13")
Set Engineer11 = .Range("A14")
Set Engineer12 = .Range("A15")
Dim PartStatus1, PartStatus2, PartStatus3, PartStatus4, PartStatus5, PartStatus6, PartStatus7, PartStatus8
With Worksheets("FilterChoiceSelection")
Set PartStatus1 = .Range("C6")
Set PartStatus2 = .Range("C7")
Set PartStatus3 = .Range("C8")
Set PartStatus4 = .Range("C9")
Set PartStatus5 = .Range("C10")
Set PartStatus6 = .Range("C11")
Set PartStatus7 = .Range("C12")
End With
Dim StatusCode1, StatusCode2, StatusCode3, StatusCode4, StatusCode5
With Worksheets("FilterChoiceSelection")
Set StatusCode1 = .Range("E6")
Set StatusCode2 = .Range("E7")
Set StatusCode3 = .Range("E8")
Set StatusCode4 = .Range("E9")
Set StatusCode5 = .Range("E10")
End With
Dim RowCount
With Worksheets("CalcData")
Set RowCount = .Range("B2")
Dim Copyrange As String
Lastrow = RowCount
Copyrange = "A1:DE" & Lastrow
End With
With Worksheets("Data")
.AutoFilterMode = False
With .Range(Copyrange)
.AutoFilter 9, Array(Engineer1, Engineer2, Engineer3, Engineer4, Engineer5, Engineer6, Engineer7), Operator:=xlFilterValues
.AutoFilter 16, Array(PartStatus1, PartStatus2), Operator:=xlFilterValues
.AutoFilter 17, Array(StatusCode1, StatusCode2), Operator:=xlFilterValues
End With
End With
End With
End Sub
Last edited by a moderator: