【问题标题】:Avoid duplicates in Excel 2007在 Excel 2007 中避免重复
【发布时间】:2018-09-17 19:59:10
【问题描述】:

我需要将数据从Sheet 1 Column A 提取到Sheet 2 Column ASheet 2 已经在 Column A 中有一些值。所以,我需要一个公式来将数据从Sheet 1 Column A 拉到Sheet 2。如果值已经存在,则不需要复制,如果不需要拉数据。

例如:
Sheet 2 我写了一个公式,例如:如果ID 已经存在于Sheet 1 中,则将标记添加到现有的。
@987654321 @

Sheet 1 需要编写如下公式:如果IDSheet 2 的新成员,则将ID 添加到带有标记的下一行。

每两周将IDs 和标记添加到Sheet 1。所以,我需要Sheet 2 成为一个统一的。提前感谢您的帮助。

【问题讨论】:

  • ...所以,你真正的“问题”是“有人会为我写代码吗?”

标签: excel excel-formula duplicates excel-2007


【解决方案1】:

试试

Option Explicit

Public Sub CopyUniqueOnly()

    Dim currCell As Range, dict As Object
    Set dict = CreateObject("Scripting.Dictionary")

    With ThisWorkbook.Worksheets("Sheet2")
        For Each currCell In .Range("A1", .Cells(.Rows.count, 1).End(xlUp))
            If Not dict.exists(currCell.Value) And Not IsEmpty(currCell) Then
                dict.Add currCell.Value, currCell.Value
            End If
        Next currCell
    End With

    Dim unionRng As Range

    With ThisWorkbook.Worksheets("Sheet1")
        Dim rng As Range
        For Each rng In .Range("A1", .Cells(.Rows.count, 1).End(xlUp))
            If Not dict.exists(rng.Value) And Not IsEmpty(rng) Then
                If Not unionRng Is Nothing Then
                    Set unionRng = Union(rng, unionRng)
                Else
                    Set unionRng = rng
                End If
            End If
        Next rng
    End With

    With ThisWorkbook.Worksheets("Sheet2")
        If Not unionRng Is Nothing Then unionRng.EntireRow.Copy .Cells(.Rows.count, 1).End(xlUp).Offset(1, 0)
    End With

End Sub

或者

将表 1 中的所有数据复制到表 2,然后只使用内置数据 > 删除重复项并指定 A 列

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    相关资源
    最近更新 更多