VBA Code to highlight highest valued cell in yellow

Cquake

Board Regular
Joined
Dec 12, 2017
Messages
57
Office Version
  1. 2016
Platform
  1. Windows
On the following table below I would like to have the highest valued number to highlight with each roll. I would like to code in in VBA. I have looked at different sites but so far have had no luck finding what I need. Thanks for any help one can give me.

Momentum Roll (Step 1)
Offense82
Defense63
Momentum49
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this:
VBA Code:
Sub HighestValue()
Dim i As Long, j As Long, Lr As Long, M As Double
Lr = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:B" & Lr).Interior.Color = 16777215
M = Range("B2:B" & Lr).Find(Application.WorksheetFunction.Max(Range("B2:B" & Lr))).Row
Range("A" & M & ":B" & M).Interior.Color = vbYellow
End Sub
 
Upvote 0
I would like to code in in VBA.
Is there a particular reason that you wouldn't just apply standard Conditional Formatting and leave it there for each roll?

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Try this:
VBA Code:
Sub HighestValue()
Dim i As Long, j As Long, Lr As Long, M As Double
Lr = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:B" & Lr).Interior.Color = 16777215
M = Range("B2:B" & Lr).Find(Application.WorksheetFunction.Max(Range("B2:B" & Lr))).Row
Range("A" & M & ":B" & M).Interior.Color = vbYellow
End Sub
Thanks for the help. It worked perfectly.
 
Upvote 0
Is there a particular reason that you wouldn't just apply standard Conditional Formatting and leave it there for each roll?

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
To be honest when it comes to conditional formatting I know how to use it for certain things but wasn't sure what the right steps were to highlight the highest number. I mainly only have used it for situations for "equal to". Updated my info hopefully correctly.
 
Upvote 0
Updated my info hopefully correctly.
Thanks for updating your profile. (y)

.. wasn't sure what the right steps were to highlight the highest number.
Suppose the roll values are going in to column B, starting at row2.
  1. Select B2 down to wherever the last roll value is or might ever be.
  2. Conditional Formatting -> New rule ... -> Use a formula to determine which cells to format -> Format values where this formula is true:- =AND(B2=MAX(B$2:B$10),B2<>"") -> Format... -> Fill tab -> Choose your colour -> OK -> OK.
    In that formula where I have 10, use the row number of the last cell selected in step 1 above
Once you have that set up it should highlight the largest value wherever it occurs in that range of cells (unless you have other vba that removes the existing CF)

21 08 22.xlsm
B
1
22
35
46
54
6
7
8
9
10
CF Max
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B10Expression=AND(B2=MAX(B$2:B$10),B2<>"")textNO
 
Upvote 0
Thanks for updating your profile. (y)


Suppose the roll values are going in to column B, starting at row2.
  1. Select B2 down to wherever the last roll value is or might ever be.
  2. Conditional Formatting -> New rule ... -> Use a formula to determine which cells to format -> Format values where this formula is true:- =AND(B2=MAX(B$2:B$10),B2<>"") -> Format... -> Fill tab -> Choose your colour -> OK -> OK.
    In that formula where I have 10, use the row number of the last cell selected in step 1 above
Once you have that set up it should highlight the largest value wherever it occurs in that range of cells (unless you have other vba that removes the existing CF)

21 08 22.xlsm
B
1
22
35
46
54
6
7
8
9
10
CF Max
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B10Expression=AND(B2=MAX(B$2:B$10),B2<>"")textNO
Thank you for that info.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top