Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 我需要检查目标工作表中是否已经有行,如果是,我不&x27;I don’我不想让它复制并复制_Excel_Vba - Fatal编程技术网

Excel 我需要检查目标工作表中是否已经有行,如果是,我不&x27;I don’我不想让它复制并复制

Excel 我需要检查目标工作表中是否已经有行,如果是,我不&x27;I don’我不想让它复制并复制,excel,vba,Excel,Vba,如问题中所述,我可以使用自动筛选将行从源工作表复制并粘贴到目标工作表,但我只尝试引入新行或更改的行,知道如何做到这一点吗?使用范围。查找或应用程序。匹配以测试公共标识符目标工作表中已经有。@BigBen您是否可以提供一个id如何使用range.find的代码内示例?@Gmx5000请随意搜索其中任何一项。关于如何使用它,有很多例子。如何识别重复记录?行中的所有单元格都匹配,还是存在唯一标识的键字段。一个源工作表平均有多少条记录?@basodre行中的所有单元格都需要匹配,因为有时只有一个单元格被

如问题中所述,我可以使用自动筛选将行从源工作表复制并粘贴到目标工作表,但我只尝试引入新行或更改的行,知道如何做到这一点吗?

使用
范围。查找
应用程序。匹配
以测试公共标识符目标工作表中已经有。@BigBen您是否可以提供一个id如何使用range.find的代码内示例?@Gmx5000请随意搜索其中任何一项。关于如何使用它,有很多例子。如何识别重复记录?行中的所有单元格都匹配,还是存在唯一标识的键字段。一个源工作表平均有多少条记录?@basodre行中的所有单元格都需要匹配,因为有时只有一个单元格被更改,而我需要该记录。这张纸平均大约有100行
Sub Copy_Amazon()
    Dim src As Worksheet
    Dim tgt As Worksheet
    Dim filterRange As Range
    Dim copyRange As Range
    Dim lastRow As Long
    Dim DestLastRow As Long
    
    Set src = Workbooks("AMZN COMBINED.xlsm").Worksheets("AMZN")
    Set tgt = Workbooks("Archive_Dispatched.xlsx").Worksheets("Amazon")

    ' turn off any autofilters that are already set
    src.AutoFilterMode = False
 
    ' find the last row with data in column A
    lastRow = src.Range("A" & src.Rows.Count).End(xlUp).Row

    ' the range that we are auto-filtering (all columns)
    Set filterRange = src.Range("A1 :O" & lastRow)

    ' the range we want to copy (only columns we want to copy)
    ' in this case we are copying country from column A
    ' we set the range to start in row 2 to prevent copying the header
    Set copyRange = src.Range("A2:O" & lastRow)

    ' filter range based on column J
    filterRange.AutoFilter field:=5, Criteria1:="D"

    ' copy the visible cells to our target range
    DestLastRow = tgt.Cells(tgt.Rows.Count, "A").End(xlUp).Offset(1).Row
    copyRange.SpecialCells(xlCellTypeVisible).Copy tgt.Range("A" & DestLastRow)
    
    'Turn off Auto Filter again
    src.AutoFilterMode = False

End Sub