DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

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 & 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
Example range

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

Select Visual Basic option
Select the Visual Basic option

  • 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
Save the code

  • 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
Choose the Macros option

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

Hit the Run button
Hit the Run button

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

Output
Output

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. Keep Learning!

Keep Reading:

Top comments (0)