Conditional Formating Excel Table

flipland

New Member
Joined
Mar 26, 2019
Messages
9
Hi. I would like to have conditional formatting done on an Excel Table based on the MIN and MAX values of every row in the table. Cells of the MIN values are to be highligted in RED with WHITE font. Celss of the MAX values are to be highlighted in GREEN with WHITE font.

I was able to find VBA code to conditionally format by row, but am stuck as to how to make it loop down to the next row. The code is copy-pasted below, as well as a snippet of the table. Would appreciate any help on this. Thanks!

CODE:
Public Sub MIN_MAX_Format()

ActiveSheet.Range("A1").Select
ActiveCell.Offset(1, 1).Select
Range("b2:r2").Select


Dim rg As Range
Dim cond1 As FormatCondition, cond2 As FormatCondition, cond3 As FormatCondition
Set rg = ActiveSheet.Range("B2:R2")

'clear any existing conditional formatting
rg.FormatConditions.Delete

'define the rule for each conditional format
Set cond1 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=$U2")
Set cond2 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=$T2")

'define the format applied for each conditional format
With cond1
.Interior.Color = vbGreen
.Font.Color = vbWhite
End With

With cond2
.Interior.Color = vbRed
.Font.Color = vbWhite
End With

ActiveCell.Offset(1, 0).Select


End Sub



The table looks like this:

https://drive.google.com/file/d/1yTWNE9WaHTzBJRUfXZ_VKq5v8ZdJZdFf/view?usp=sharing

Country NameBangladeshBhutanChinaHong Kong SAR, ChinaIndonesiaJapanLao PDRSri LankaMacao SAR, ChinaMyanmarMalaysiaNepalPhilippinesSingaporeThailandVietnamKorea, Rep.MINMAX
196089904294791432355125442810115851479
19619776437564143226522674491079452564
1962100714886341392305515747211410655634

<tbody>
</tbody>
 
You're welcome & thanks for the feedback
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,942
Messages
6,122,367
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