So I have the below code which works perfectly (maybe could be cleaned up a little but its working) what im trying to figure out if right now if column I changed then it runs the sort or if "ETOX-SKIP" is selected from the drop down in column D then it sorts.
The thing im trying to figure out is if there a way to trigger the event if column D is changed from "ETOX-SKIP" to anything else then trrigger the sort.
I dont wanna sort with every single change on the page just buy the two current criteria and as I said if it is changed from "ETOX-SKIP"
Thanks in advance.
The thing im trying to figure out is if there a way to trigger the event if column D is changed from "ETOX-SKIP" to anything else then trrigger the sort.
I dont wanna sort with every single change on the page just buy the two current criteria and as I said if it is changed from "ETOX-SKIP"
Thanks in advance.
Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
Dim SS As Worksheet: Set SS = ThisWorkbook.Sheets("Steri Sheet")
Dim ST As ListObject: Set ST = SS.ListObjects("SteriTable")
Dim SteriS As Range: Set SteriS = Range("SteriTable[DEST LOC ID]")
Dim SteriST As Range: Set SteriST = Range("SteriTable[STATE]")
Dim SteriZ As Range: Set SteriZ = Range("SteriTable[ZIP CODE]")
On Error Resume Next
'---------------------Sort by Loc ID-----------------------------
If Not Intersect(Target, Range("I:I")) Is Nothing Then
With ST.Sort
.SortFields.Clear
.SortFields.Add Key:=SteriS, SortOn:=xlSortOnValues, Order:=xlAscending _
, CustomOrder:="ETOX,ETOXCNWY,ETOXNMTF,ETOXODFL,ETOXFXFE,ETOXLMEL,ETOXGGJ,ETOXMSP,ETOXREPL,EDC/WDC,ETOX-SKIP" _
, DataOption:=xlSortNormal
.SortFields.Add Key:=SteriST, SortOn:=xlSortOnValues, Order:=xlAscending _
, DataOption:=xlSortNormal
.SortFields.Add Key:=SteriZ, SortOn:=xlSortOnValues, Order:=xlAscending _
, DataOption:=xlSortNormal
.Apply
Range("F10").Select
End With
End If
'----------------SOrt if ETOX-SKIP is selected-------------------------------------
If Not Intersect(Target, Range("D:D")).Value = "ETOX-SKIP" Then
Exit Sub
Else
With ST.Sort
.SortFields.Clear
.SortFields.Add Key:=SteriS, SortOn:=xlSortOnValues, Order:=xlAscending _
, CustomOrder:="ETOX,ETOXCNWY,ETOXNMTF,ETOXODFL,ETOXFXFE,ETOXLMEL,ETOXGGJ,ETOXMSP,ETOXREPL,EDC/WDC,ETOX-SKIP" _
, DataOption:=xlSortNormal
.SortFields.Add Key:=SteriST, SortOn:=xlSortOnValues, Order:=xlAscending _
, DataOption:=xlSortNormal
.SortFields.Add Key:=SteriZ, SortOn:=xlSortOnValues, Order:=xlAscending _
, DataOption:=xlSortNormal
.Apply
Range("F10").Select
End With
End If
End Sub