excel - 我需要检查目标工作表中是否已经有一行,如果是,我不希望它复制并创建重复项
问题描述
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
如问题所述,我可以使用自动过滤器将行从源复制并粘贴到目标工作表,但我试图只引入新行或更改的行,关于我如何做到这一点的任何想法?
解决方案
推荐阅读
- xamarin.forms - Xamarin 表单 PropertyChanged 对象为空
- r - 错误:“命名空间:ff”未导出对象“克隆”
- spring - 如何从 com.ibm.mq.MQException 中恢复:MQJE001:完成代码“2”,原因“2009”
- python - Python:要求用户输入数字,选择1则打印文本,否则退出程序
- php - WordPress 和 WPBakery 更新后无法加载更多帖子项目
- r - 在 R 中解析 XML-TEI 并转换为语料库
- java - 如何在 Java 中找到质数?
- windows - 检查批处理文件是否在PowerShell中成功运行
- javascript - Facebook Instant Game JS Cookie Chrome 错误
- excel - Excel VBA - 条件格式,索引不包含在间隔中