复制/粘贴/排序多列
在下面的脚本中复制/粘贴数据问题。计划将原始数据从列T,C,R
列为列x,y,z
然后对列x
降序。开始使用索引/匹配,但更易于复制/粘贴/排序。由于Worksheet_calc事件,将必须复制/粘贴/对每毫秒进行复制/排序。
Private Sub Worksheet_Calculate()
Dim total_data As Range
Dim specific_column As Range
If Worksheets("Dashboard").ToggleButton1.Value = True Then
On Error GoTo SafeExit
Application.EnableEvents = False
Application.ScreenUpdating = False
Set sht1 = ThisWorkbook.Sheets("Log")
Set cpyRng = sht1.Range("T3:T60000,C3:C60000,R3:R60000")
Set pstRng = sht1.Range("X3:X60000,Y3:Y60000,Z3:Z60000")
cpyRng.Copy
pstRng.PasteSpecial xlPasteValues
Application.CutCopyMode = False ' Remove the copy area marker
Set total_data = Worksheets("Log").Range("X:Z")
Set specific_column = Worksheets("Log").Range("X:X")
total_data.Sort Key1:=specific_column, Order1:=xlDescending, Header:=xlYes
Worksheets("Log").Cells(1, 1).Select
End If
SafeExit:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Having issues copying/pasting data in script below. Plan to copy raw data from Columns T,C,R
to Columns X,Y,Z
then sort Column X
descending. Started using Index/Match but easier to copy/paste/sort. Will have to copy/paste/sort every millisecond due to Worksheet_Calc event.
Private Sub Worksheet_Calculate()
Dim total_data As Range
Dim specific_column As Range
If Worksheets("Dashboard").ToggleButton1.Value = True Then
On Error GoTo SafeExit
Application.EnableEvents = False
Application.ScreenUpdating = False
Set sht1 = ThisWorkbook.Sheets("Log")
Set cpyRng = sht1.Range("T3:T60000,C3:C60000,R3:R60000")
Set pstRng = sht1.Range("X3:X60000,Y3:Y60000,Z3:Z60000")
cpyRng.Copy
pstRng.PasteSpecial xlPasteValues
Application.CutCopyMode = False ' Remove the copy area marker
Set total_data = Worksheets("Log").Range("X:Z")
Set specific_column = Worksheets("Log").Range("X:X")
total_data.Sort Key1:=specific_column, Order1:=xlDescending, Header:=xlYes
Worksheets("Log").Cells(1, 1).Select
End If
SafeExit:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在X3中使用公式(如果使用Excel 365) - 它将以新顺序溢出所有三列并对其进行排序,
或者您在VBA中使用此公式,然后将输出切换到值-STH。喜欢:
You can use a formula in X3 (if you use Excel 365) - it will spill down all three columns in the new order and sort them
Or you use this formula in VBA and then switch the output to values - sth. like: