duteberta
Board Regular
- Joined
- Jun 14, 2009
- Messages
- 92
- Office Version
- 365
- Platform
- MacOS
Given: Table Name = "MASTER"
Given: Column where change would trigger macro = "Status" (currently column 3 of table)
Given: Sort Macro =
+++++++
Question: How do I write VBA code to trigger the above macro? I know the macro works because I've tested it. However I cannot get this trigger based on cell change in column 3.
Context: I already have another script running on the same worksheet that I'm worried is conflicting with what I'm attempting to do....
++++
++++
Given: Column where change would trigger macro = "Status" (currently column 3 of table)
Given: Sort Macro =
VBA Code:
Sub SortTable()
Dim iSheet As Worksheet
Dim iTable As ListObject
Dim iColumn As Range
Set iSheet = ActiveSheet
Set iTable = iSheet.ListObjects("MASTER")
Set iColumn1 = Range("MASTER[Status]")
Set iColumn2 = Range("MASTER[CloseD]")
Set iColumn3 = Range("MASTER[C1]")
With iTable.Sort
.SortFields.Clear
.SortFields.Add Key:=iColumn1, Order:=xlAscending
.SortFields.Add Key:=iColumn2, Order:=xlDescending
.SortFields.Add Key:=iColumn3, Order:=xlAscending
.Header = xlYes
.Apply
End With
End Sub
Question: How do I write VBA code to trigger the above macro? I know the macro works because I've tested it. However I cannot get this trigger based on cell change in column 3.
Context: I already have another script running on the same worksheet that I'm worried is conflicting with what I'm attempting to do....
++++
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim tbl As ListObject
Dim rngCell As Range
If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next
Set tbl = Target.Worksheet.ListObjects(1)
If tbl Is Nothing Then Exit Sub
If tbl.ListRows.Count = 0 Then Exit Sub
Set rngCell = Application.Intersect(tbl.ListColumns("X").DataBodyRange, Target)
If rngCell Is Nothing Then Exit Sub
On Error GoTo 0
tbl.ListColumns("X").DataBodyRange = ""
rngCell.Value = 1
End Sub
Last edited by a moderator: