Mat*_*att 6 sorting microsoft-excel microsoft-excel-2013
有没有办法自动重新排序?我已自动更新单元格,并根据传入的值更改排名。我正在寻找一种无需单击重新排序按钮即可自动使用表格度假村的方法(类似于条件格式)。
这里的目标是纯粹通过内置的 Excel2013 函数来完成这样的工作。我不是在寻找涉及辅助排序的其他单元格的解决方案,例如 Rank(),...
编辑
我包含了一个宏的代码,它以设定的时间间隔刷新工作簿,还包含一个工作表中的代码,该代码应该刷新 Worksheet_Calculate 上那张工作表上的表格。我收到一个运行时错误,不确定是什么问题?
Public RunWhen As Double
Const frequency = 5
Const cRunWhat = "DoIt" ' the name of the procedure to run
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, frequency)
Application.OnTime RunWhen, cRunWhat, Schedule:=True
End Sub
Sub DoIt()
Sheets("RAWDATA").Calculate
ActiveSheet.Calculate
StartTimer ' Reschedule the procedure
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime RunWhen, cRunWhat, Schedule:=False
End Sub
Run Code Online (Sandbox Code Playgroud)
以及据称刷新表格的代码
Private Sub Worksheet_Calculate()
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
ActiveSheet.ListObjects("Table2").AutoFilter.ApplyFilter
With ActiveWorkbook.Worksheets("Strategies").ListObjects("Table2").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.ListObjects("Table3").AutoFilter.ApplyFilter
With ActiveWorkbook.Worksheets("Strategies").ListObjects("Table3").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
他评论说,当问题已经得到解答时,我不喜欢留下悬而未决的问题。您可以在评论中阅读历史记录,但这是最终的解决方案:
Private Sub Worksheet_Calculate()
'If the active sheet is called "Strategies", then this reapplies the filter for two tables and re-sorts them
Const wsName As String = "Strategies"
If ActiveSheet.Name = wsName Then
'Freeze everything and turn off events
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
'Update Table2
With Worksheets(wsName).ListObjects("Table2")
.AutoFilter.ApplyFilter
With .Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
'Update Table3
With Worksheets(wsName).ListObjects("Table3")
.AutoFilter.ApplyFilter
With .Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
'Unfreeze things and turn events back on
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
您甚至可以将过滤和排序缩短为
With Worksheets(wsName).ListObjects("Table2")
.AutoFilter.ApplyFilter
.Sort.Apply
End With
Run Code Online (Sandbox Code Playgroud)
这是一个社区维基,因为我没有得出解决方案。如果需要,您可以对其进行编辑,但我所做的只是转录注释中发现的问题并稍微清理一下代码。
| 归档时间: |
|
| 查看次数: |
6449 次 |
| 最近记录: |