How to Check for duplicates in columns in excel office VBA?
Tags: tocheckforduplicates, vbamacros
Published: 2021-09-29 04:56:08

---
title: How to Check for duplicates in columns in excel office VBA?
published: true
date: 2021-09-25 14:18:10 UTC
tags: ToCheckForDuplicates,VBAMacros
canonical_url: https://geekexcel.com/how-to-check-for-duplicates-in-columns-in-excel-office-vba/
---

In this blog post, we will guide you on how to ** check for duplicates in columns** in Excel Office VBA. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, you need to  **create a sample data** with different **car names**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Sample-data-37.png)<figcaption>Sample data</figcaption>

- In the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Option Explicit
Sub Check_Dups()
'Declaring variables
Dim Cell As Variant
Dim Source As Range
'Initializing source range
Set Source = Range("A9:A24")
'Removing any previous formatting from the source
Source.Interior.Color = RGB(221, 235, 247)
'Looping through each cell in the source range
For Each Cell In Source
    'Checking whether value in cell already exist in the source range
    If Application.WorksheetFunction.CountIf(Source, Cell) > 1 Then
        'Highlighting duplicate values in red color
        Cell.Interior.Color = RGB(255, 0, 0)    
    End If
Next
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-75.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-45.png)<figcaption>Run the Code</figcaption>

- Finally, you will receive the **output ** as  **duplicates columns** in Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-36.png)<figcaption>Output</figcaption>

## Summary

We hope that this tutorial gives you guidelines on how to ** check for duplicates in columns** in Excel Office VBA. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Read Next:**

- **[Excel Formulas to Calculate Net Present Value (NPV) ~ Simple Guide!!](https://geekexcel.com/excel-formulas-to-calculate-net-present-value-npv/)**
- **[Calculate the Present Value of Annuity ~ Useful Tricks!!](https://geekexcel.com/excel-formulas-to-calculate-the-present-value-of-annuity/)**
- **[Excel Formulas to Get the Percentage Discount ~ Useful Tricks!!](https://geekexcel.com/excel-formulas-to-get-the-percentage-discount/)**
- **[use the MIRR function in Excel office 365? ~ {Quick Steps}](https://geekexcel.com/how-to-use-the-mirr-function-in-excel-office-365-quick-steps/)**
- **[Excel Formulas to Find Original Price from Percentage Discount!!](https://geekexcel.com/excel-formulas-to-find-original-price-from-percentage-discount/)**