简体   繁体   English

在Excel VBA中将数据从一张纸移动到另一张纸而无需复制粘贴

[英]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.

相关问题 使用excel VBA将数据从一张纸复制并粘贴到另一张纸,然后从第二张纸复制到第三张纸 - Copy and paste data from one a sheet to another sheet, and from second sheet to third using excel VBA Excel VBA 复制一张表的第一行数据并粘贴到另一张表 - Excel VBA to copy 1st row of data of one sheet and paste to another sheet Excel VBA脚本,用于将数据从一张纸移动到另一张纸,而不会覆盖编译错误。 - Excel VBA Script for moving data from one sheet to another without overwriting compile errors. Excel 将内容从一张纸复制到另一张纸,无需 VBA/宏 - Excel copy contents from one sheet to another without VBA/Macro 使用VBA excel从一张工作表中复制表格并将其粘贴到另一张工作表的下一个空行中 - copy a table from one Sheet and paste it in the next empty row of another Sheet using VBA excel Excel Vba-如何将匹配的行从一个工作表复制并粘贴到另一工作表中的完全匹配的行以下 - Excel Vba - How to copy and paste matched rows from one sheet to below exact matched rows in another sheet Excel使用VBA将数据从一张纸复制到工作表上的另一张 - Excel copy data from one sheet to another on worksheet refresh with vba Excel 使用 VBA 将单元格数据从一张纸复制到另一张纸 - Excel Copy Cell Data from one sheet to another using VBA 如果条件匹配(但不是+1),excel vba从另一个工作表复制/粘贴数据 - excel vba to copy/paste data fron another sheet if conditions match (but not +1) excel vba如果条件匹配,则从另一张表复制/粘贴数据 - excel vba to copy/paste data fron another sheet if conditions match
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM