Loop Through Rows and Highlight Cells

rob51852

Board Regular
Joined
Jun 27, 2016
Messages
190
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a sheet that contains 3 rows of data. The top row contains benchmark data and the other two rows are results. The XL2BB is below.

I would like a macro to loop through the two results rows and highlight any cell (by using a different colour fill) that is 5% greater than the benchmark value in the same column.

Is this possible?

Thanks


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
56162.986.5424.93135.9216.05148.576.1424.18134.7316.3324.74142.7118.2324.35124.6713.2130.31132.6019.8726.45128.9413.1417.02162.1719.31243.00115.0046.8551.102.05
57156.756.7523.22130.6315.10145.386.8821.15128.0814.9822.78137.5816.9721.35119.0312.6129.77113.7216.3218.18117.4011.6725.40191.2722.59168.00149.0050.0050.000.00
58157.756.7524.22120.6314.10145.387.8821.15129.0813.9822.78137.5816.9721.35129.0322.6129.77113.7226.3218.18113.4011.6721.40191.2725.59162.00149.0051.0053.000.00
Summary
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Why not just use conditional formatting?
+Fluff New.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
56162.986.5424.93135.9216.05148.576.1424.18134.7316.3324.74142.7118.2324.35124.6713.2130.31132.619.8726.45128.9413.1417.02162.1719.3124311546.8551.12.05
57156.756.7523.22130.6315.1145.386.8821.15128.0814.9822.78137.5816.9721.35119.0312.6129.77113.7216.3218.18117.411.6725.4191.2722.5916814950500
58157.756.7524.22120.6314.1145.387.8821.15129.0813.9822.78137.5816.9721.35129.0322.6129.77113.7226.3218.18113.411.6721.4191.2725.5916214951530
Data
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A57:AD58Expression=A57>=A$56*1.05textNO
 
Upvote 0
Rather than VBA, wouldn't conditional formatting be a lot easier, for that?
 
Upvote 0
Thanks guys. There are a few macros in the sheet that are run by a user clicking a button and I'd like to add a macro to that if possible.
 
Upvote 0
Hi Pls try below code
VBA Code:
Sub Highlight_Cells()
    Dim lc As Long
    Dim c As Range
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    For Each c In Range(Cells(2, 1), Cells(3, lc))
        If c.Value - Cells(1, c.Column).Value >= 5 Then
            c.Interior.Color = vbGreen
        End If
    Next
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub rob()
   Dim r As Long, c As Long
   
   For r = 57 To 58
      For c = 1 To 30
         If Cells(r, c) >= Cells(56, c) * 1.05 Then Cells(r, c).Interior.Color = 45678
      Next c
   Next r
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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