简体   繁体   English

Excel基于一个列的值将整个行从一张纸复制到另一张纸

[英]Excel Copy whole row from a sheet to another sheet based on one column value

I need to copy an entire row from a sheet and paste in another sheet with same header consider a particular column value is equal to 89581.But my VBA throws 424 error.Please help. 我需要从工作表中复制整行并粘贴到具有相同标题的另一工作表中,因为特定列值等于89581。但是我的VBA抛出424错误。请帮忙。

Sub CopyData()
Dim c As Range
Dim Row As Long
Dim sheetUse As Worksheet
Dim sheetCopy As Worksheet
Set sheetUse = Sheets("Data1").Select
Set sheetCopy = Sheets("Data2").Select
Row = 3 'Assume same  header in sheet2 as in sheet1
For Each c In sheetUse.Range("O3",  Sheet1.Range("O65536").End(xlUp))       
    If c = 89581 Then

         'copy this row to sheet2
        Row = Row + 1
        c.EntireRow.Copy sheetCopy.Cells(Row, 1)

    End If

Next c

Application.CutCopyMode = False
End Sub

Here you go, build a reference to copy then copy and paste in one go. 在这里,建立参考进行复制,然后一并复制和粘贴。

Sub CopyToOtherSheet()
Dim sheetUse As Worksheet, sheetCopy As Worksheet, i As Long, CopyRange As String
Set sheetUse = Sheets("Data1")
Set sheetCopy = Sheets("Data2")
For i = 3 To sheetUse.Cells(Rows.Count, 15).End(xlUp).Row
    If sheetUse.Cells(i, 15) = 89581 Then CopyRange = CopyRange & "," & i & ":" & i
Next i
sheetUse.Range(Right(CopyRange, Len(CopyRange) - 1)).Copy
sheetCopy.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll 'Change to values or formats or whatever you want
Application.CutCopyMode = False
End Sub

Assumed Data1 is the sheet with the data in and Data2 is the one to copy to. 假设Data1是其中包含数据的工作表,而Data2是要复制到其中的工作表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法将列值从一个工作表复制到另一个工作表作为基于第一个分组的行 - is there any way to copy column values from one sheet to another sheet as row based on sheet one grouping 根据列中的条件将行从一个工作表复制到另一个工作表 - Copy row from one sheet to another based on criteria in a column Excel宏可根据单元格值将一行中的选定单元格从一张纸复制到另一张纸 - Excel Macro to copy select cells from a row from one sheet to another based upon a cell value Excel宏-根据值将单元格从一张纸复制到另一张纸 - Excel Macro - copy cells from one sheet into another based on value 如何根据单元格值将行内的范围从一个 Excel 工作表复制到另一个 - How to copy a range within a row from one excel sheet to another based on a cell value Excel VBA 根据第二列单元格值将列从一张表复制到另一张表 - Excel VBA to Copy Column from one sheet to another based on a second columns cell value 尝试根据 A 列中的值将一行及其之前的行复制到另一张工作表 - trying to copy a row and the row before it to another sheet based on a value in column A 根据另一张纸上的订单号从一张纸上查找列值 - Find column value from one sheet based on the order # on another sheet 将一行从一张纸复制到另一张纸的另一行 - copy one row from one sheet to another row in another sheet 如果在 Excel 中标有“X”,则将行从一张纸复制到另一张纸 - Copy Row From One Sheet to Another if Marked with "X" in Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM