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.
- On the Developer Tab, select the Visual Basic option under the Code section.
- 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.
- You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.
- You need to make sure that your macro is selected and click the Run button.
- At last, you will get the result as shown in the below screenshot.
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!
Top comments (0)