DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

Highlight Max Value in Selection using Macros (VBA) in Excel 365!!

In this tutorial, we are going to look at how to highlight the largest value in the selected range with Macros in Excel. VBA & Macros will make this work as simple as possible. Because we are going to do this with a few clicks. Let’s see the clear-cut instructions to highlight the max value in Selection using Macros in Excel Office 365.

Highlight Max Value in the Selection:

To select or highlight the largest value in the range, do as follows.

  • In the below image, you can see the set of input values in the range B1:B10. We are going to find and highlight the largest value from this range.

Example
Example

  • 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 max value using Macros

Sub HighlightMaxVal()

Dim cell As Range

For Each cell In Selection

If cell = WorksheetFunction.Max(Selection) Then

cell.Style = “Note”

End If

Next cell

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.

Macros dialog box
Macros dialog box

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

Result
Result

Summary:

In this tutorial, we have demonstrated the clear-cut instructions to highlight the max value in Selection using Macros in Excel Office 365. Leave your feedback in the below comment section. Thanks for visiting Geek Excel. Keep Learning!

Also Read:

Top comments (0)