Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

您可以使用下列方法來比較兩個 Microsoft Excel 工作表欄中的資料,並尋找重複項目。 

方法 1: 使用工作表公式

  1. 啟動 Excel。

  2. 在新的工作表中,輸入下列資料做為範例 (將欄 B 保留空白):

    A

    B

    C

    1

    1

    3

    2

    2

    5

    3

    3

    8

    4

    4

    2

    5

    5

    0

  3. 在儲存格 B1 中輸入下列公式:

    =IF(ISERROR(MATCH(A1,$C$1:$C$5,0)),"",A1)

  4. 選取儲存格 B1 到 B5。

  5. 在 Excel 2007 及更新版本的 Excel 中,選取 [編輯] 群組中的 [填滿],然後選取 [向下]

    重複的數字會顯示在欄 B 中,如下列範例所示: 

    A

    B

    C

    1

    1

    3

    2

    2

    2

    5

    3

    3

    3

    8

    4

    4

    2

    5

    5

    5

    0

方法 2: 使用 Visual Basic 巨集

警告: Microsoft 僅提供圖例的程式設計範例,不含明示或暗示的擔保。 這包括 (但不限於) 適用于特定目的之可操作性或適用性的暗示擔保。 本文假設您熟悉正在示範的程式設計語言,以及用來建立和進行程式偵錯工具的工具。 Microsoft 支援工程師可以協助說明特定程式的功能。 不過,他們將不會修改這些範例以提供新增功能或建構符合您特定需求的程式。

若要使用 Visual Basic 巨集來比較兩欄的資料,請使用下列範例中的步驟:

  1. 啟動 Excel。

  2. 按 ALT+F11 以啟動 Visual Basic 編輯器。

  3. [插入] 功能表上選取 [模組]

  4. 在模組工作表中輸入下列程式碼:

    Sub Find_Matches()
    Dim CompareRange As Variant, x As Variant, y As Variant
    ' Set CompareRange equal to the range to which you will
    ' compare the selection.
    Set CompareRange = Range("C1:C5")
    ' NOTE: If the compare range is located on another workbook
    ' or worksheet, use the following syntax.
    ' Set CompareRange = Workbooks("Book2"). _
    ' Worksheets("Sheet2").Range("C1:C5")
    '
    ' Loop through each cell in the selection and compare it to
    ' each cell in CompareRange.
    For Each x In Selection
    For Each y In CompareRange
    If x = y Then x.Offset(0, 1) = x
    Next y
    Next x
    End Sub
  5. 按 ALT+F11 返回 Excel。

    1. 輸入下列資料做為範例 (將欄 B 保留空白):
       

      A

      B

      C

      1

      1

      3

      2

      2

      5

      3

      3

      8

      4

      4

      2

      5

      5

      0

  6. 選取儲存格 A1 到 A5。

  7. 在 Excel 2007 及更新版本的 Excel 中,選取 [開發人員] 索引標籤,然後在 [程式碼] 群組中選取 [巨集]

    附註: 如果您看不到 [開發人員] 索引標籤,您可能需要將其開啟。 若要這樣做,請選取 [檔案] > [選項] > [自訂功能區],然後選取右側自訂方塊中的 [開發人員] 索引標籤。

  8. 按一下 Find_Matches,然後按一下 [執行]

    重複的數字會顯示在欄 B 中。符合的數字會放在第一欄旁邊,如下圖所示:

    A

    B

    C

    1

    1

    3

    2

    2

    2

    5

    3

    3

    3

    8

    4

    4

    2

    5

    5

    5

    0

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×