Private Sub Worksheet_Change(ByVal target As Range)
' Checks for any changes to the Worksheet limited to within
' the table named BodyRecovery or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("BodyRecovery[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Dim lobTable As ListObject
Set lobTable = ActiveSheet.ListObjects("BodyRecovery")
' Turn off any exising autofiltering on the table BodyRecovery
If ActiveSheet.ListObjects("BodyRecovery").ShowAutoFilter Then
ActiveSheet.ListObjects("BodyRecovery").Range.AutoFilter
End If
' Turn on autofiltering on the table BodyRecovery
ActiveSheet.ListObjects("BodyRecovery").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Dim rngKey As Range
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Dim rng As Range
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Body Recovery"), but could be changed to find that column
' Show only the "Yes" rows for "Body Recovery"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named LogisticsDriving or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("LogisticsDriving[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("LogisticsDriving")
' Turn off any exising autofiltering on the table LogisticsDriving
If ActiveSheet.ListObjects("LogisticsDriving").ShowAutoFilter Then
ActiveSheet.ListObjects("LogisticsDriving").Range.AutoFilter
End If
' Turn on autofiltering on the table LogisticsDriving
ActiveSheet.ListObjects("LogisticsDriving").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Logistics Driving"), but could be changed to find that column
' Show only the "Yes" rows for "Logistics Driving"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named Outpatients or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("Outpatients[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("Outpatients")
' Turn off any exising autofiltering on the table LogisticsDriving
If ActiveSheet.ListObjects("Outpatients").ShowAutoFilter Then
ActiveSheet.ListObjects("Outpatients").Range.AutoFilter
End If
' Turn on autofiltering on the table Outpatients
ActiveSheet.ListObjects("Outpatients").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Out Patients"), but could be changed to find that column
' Show only the "Yes" rows for "Out Patients"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named LogisticsExternal or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("LogisticsExternal[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("LogisticsExternal")
' Turn off any exising autofiltering on the table LogisticsDriving
If ActiveSheet.ListObjects("LogisticsExternal").ShowAutoFilter Then
ActiveSheet.ListObjects("LogisticsExternal").Range.AutoFilter
End If
' Turn on autofiltering on the table LogisticsExternal
ActiveSheet.ListObjects("LogisticsExternal").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Logistics External"), but could be changed to find that column
' Show only the "Yes" rows for "Logistics External"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named GeneralSupport or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("GeneralSupport[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("GeneralSupport")
' Turn off any exising autofiltering on the table GeneralSupport
If ActiveSheet.ListObjects("GeneralSupport").ShowAutoFilter Then
ActiveSheet.ListObjects("GeneralSupport").Range.AutoFilter
End If
' Turn on autofiltering on the table GeneralSupport
ActiveSheet.ListObjects("GeneralSupport").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "General Support External"), but could be changed to find that column
' Show only the "Yes" rows for "General Support External"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named CallHandling or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("CallHandling[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("CallHandling")
' Turn off any exising autofiltering on the table CallHandling
If ActiveSheet.ListObjects("CallHandling").ShowAutoFilter Then
ActiveSheet.ListObjects("CallHandling").Range.AutoFilter
End If
' Turn on autofiltering on the table CallHandling
ActiveSheet.ListObjects("CallHandling").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Call Handling"), but could be changed to find that column
' Show only the "Yes" rows for "Call Handling"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named BlueLight or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("BlueLight[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("BlueLight")
' Turn off any exising autofiltering on the table BlueLight
If ActiveSheet.ListObjects("BlueLight").ShowAutoFilter Then
ActiveSheet.ListObjects("BlueLight").Range.AutoFilter
End If
' Turn on autofiltering on the table BlueLight
ActiveSheet.ListObjects("BlueLight").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Blue Light Driving"), but could be changed to find that column
' Show only the "Yes" rows for "Blue Light Driving"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
' Checks for any changes to the Worksheet limited to within
' the table named Other or cell B2 (date entered) only. Changes to other cells will
' be ignored
If Not (Application.Intersect(ActiveSheet.Range("Other[#all]"), target) Is Nothing) Or _
Not (Application.Intersect(ActiveSheet.Range("B2"), target) Is Nothing) Then
Set lobTable = ActiveSheet.ListObjects("Other")
' Turn off any exising autofiltering on the table Other
If ActiveSheet.ListObjects("Other").ShowAutoFilter Then
ActiveSheet.ListObjects("Other").Range.AutoFilter
End If
' Turn on autofiltering on the table Other
ActiveSheet.ListObjects("Other").Range.AutoFilter
' Sort by the "Sort" column, ascending, so that the desired
' order is displayed.
Set rngKey = lobTable.ListColumns("Sort").Range
lobTable.Sort.SortFields.Clear
With lobTable
With .Sort
.SortFields.Add Key:=rngKey, CustomOrder:=xlAscending
.Header = xlYes
.Apply
End With
End With
Set rng = lobTable.Range
With rng
' This is hardcoded to column 4 (i.e. "Other"), but could be changed to find that column
' Show only the "Yes" rows for "Other"
.AutoFilter Field:=4, Criteria1:="Yes" ' This is hardcoded to column 13 (i.e. "Date"), but could be changed to find that column
' Show only the rows *without* the date entered in cell B2 (because the person has
' work that day). Also force MM/DD/YYYY as that seems to be necessary for it to work.
.AutoFilter Field:=13, Criteria1:="<>" & Month(Cells(2, 2)) & "/" & Day(Cells(2, 2)) & "/" & Year(Cells(2, 2))
End With
End If
End Sub