Highlight Unique Values in Selection using Macros in Excel 365!!
Tags: highlightuniquevalue, vbamacros
Published: 2021-02-15 09:49:02

---
title: Highlight Unique Values in Selection using Macros in Excel 365!!
published: true
date: 2021-02-15 06:34:26 UTC
tags: Highlightuniquevalue,VBAMacros
canonical_url: https://geekexcel.com/highlight-unique-values-in-selection-using-macros-in-excel-365/
---

In this tutorial, we are going to look at how to **highlight unique values in Selection using Macros** in Excel Office 365. [VBA](https://geekexcel.com/excel-office-365-vba-overview-definition-and-examples/) & Macros plays a vital role in Excel. Because it is used for completing any kind of task with a few clicks. You just follow the steps given below to achieve the task quickly.

## Highlight Unique Values in Selection:

If you want to highlight the unique values in the selected range, then you need to follow the below steps.

- In the following screenshot, you can see a **name list that contains two unique values** , and we are going to highlight them with Macros.

![Example range](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_SF8dF4zX4c.png)<figcaption id="caption-attachment-21868">Example range</figcaption>

- On the **Developer Tab, select** the **Visual Basic** option under the **Code** section.

![Select Visual Basic option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-Visual-Basic-option-4.png)<figcaption id="caption-attachment-14755">Select the Visual Basic option</figcaption>

- Then you need to copy and paste the code given below.

VBA code to highlight unique values using Macros

Sub HighlightUniqueValues()

Dim range As Range

Set range = Selection

range.FormatConditions.Delete

‘Color the unique values with green

Dim uniqueVals As UniqueValues

Set uniqueVals = range.FormatConditions.AddUniqueValues

uniqueVals.DupeUnique = xlUnique

uniqueVals.Interior.Color = RGB(152,251,152)

End Sub

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

![Save the code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_KyGyCPyCun.png)<figcaption id="caption-attachment-21865">Save the code</figcaption>

- You have to open the sheet containing the data. On the **Developer Tab, choose** the **Macros option** in the **Code** section.

![Choose the Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-the-Macros-option-2.png)<figcaption id="caption-attachment-14747">Choose the Macros option</figcaption>

- You need to make sure that your macro is selected and **click** the **Run** button.

![Hit the Run button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_1uhRMMYjuX.png)<figcaption id="caption-attachment-21866">Hit the Run button</figcaption>

- At last, you will get the result as shown in the below screenshot.

![Output](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_LnhVw9hL6A.png)<figcaption id="caption-attachment-21867">Output</figcaption>

## Summary:

In this tutorial, we have learned the easy steps to **highlight unique values in Selection using Macros** in Excel Office 365. Drop your **feedback** in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

#### Keep Reading:

- [Remove Extra Spaces from Selection Using Macros (VBA) in Excel!!](https://geekexcel.com/remove-extra-spaces-from-selection-using-macros-vba-in-excel/)
- [Add a Degree Symbol to Selection Range using Macros (VBA) in Excel!](https://geekexcel.com/add-a-degree-symbol-to-selection-range-using-macros-vba-in-excel/)
- [Remove Characters at the Start using Macros (VBA) in Excel 365!!](https://geekexcel.com/remove-characters-at-the-start-using-macros-vba-in-excel-365/)