[英]Moving data from one sheet to another without copy paste in Excel VBA
I have a macro running in the background which takes around 30 minutes to complete. 我的宏在后台运行,大约需要30分钟才能完成。
It moves data from one sheet to another using code like this: 它使用如下代码将数据从一张纸移动到另一张纸:
.AutoFilter Field:=19, Criteria1:=Array("Rejected", "Withdrawn"), Operator:=7
If xlapp.WorksheetFunction.Subtotal(3, .Range("A2:A500000")) <> 0 Then
Set wsNew = xlapp.Sheets.Add(After:=xlapp.Sheets(xlapp.Sheets.Count))
wsNew.Name = "Rejected & Withdrawn"
wsNew.Tab.Color = RGB(255, 125, 125)
.SpecialCells(12).Copy Destination:=wsNew.Range("A1")
wsNew.Cells.EntireColumn.AutoFit
End If
The clipboard is constantly in use, meaning I can't reliably use the clipbaord when the macro is running. 剪贴板一直在使用,这意味着我无法在宏运行时可靠地使用clipbaord。
Is there a way to move (or copy) a row of data without using the clipboard? 有没有一种方法可以在不使用剪贴板的情况下移动(或复制)一行数据?
Ideally I'd like to avoid looping through the row's columns as this may increase the amount of time it takes to run the macro. 理想情况下,我希望避免循环遍历该行的各列,因为这可能会增加运行宏所需的时间。
One way is by using Advanced Filter (modify "Sheet1" so it matches your worksheet name): 一种方法是使用“高级筛选器”(修改“ Sheet1”,使其与您的工作表名称匹配):
Set wsNew = xlApp.Sheets.Add(After:=xlApp.Sheets(xlApp.Sheets.Count))
wsNew.Name = "Rejected & Withdrawn"
wsNew.Tab.Color = RGB(255, 125, 125)
With Worksheets("Sheet1")
wsNew.Range("A1").Value = .Cells(1, 19).Value
wsNew.Range("A2").Value = "Withdrawn"
wsNew.Range("A3").Value = "Rejected"
.UsedRange.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=wsNew.Range("A1:A3"), CopyToRange:=wsNew.Range("C1"), Unique:=False
End With
wsNew.Range("A:B").EntireColumn.Delete
wsNew.UsedRange.Columns.AutoFit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.