Macro to Highlight data based on criteria

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have data in Col M. Where the data is 60 or more then all the data in the row where the value is 60 or more must be highlighted in gray. for Eg if M20 is 61 then A20:M20 must be highlighted. I have written code to do this. It works well, except if there is a no value in the cell below where the value is that is 60 or more. For eg if M21 is blank , then this cell is highlighted as well in gray. I want the macro to ignore blank cells in col M i.e the blank cells and values less than 60 must be ignored

Sub Colour_Data()


Columns("A:M").Interior.ColorIndex = xlNone
For J = 10 To Range("M65536").End(xlUp).Row
If Range("M" & J).Value >= 60 Then
Range("B" & J).Resize(, 12).Interior.ColorIndex = 15
End If
Next J
End Sub

Your assistance in this regard will be most appreciated
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:
Code:
Sub Colour_Data()
Dim J as Long
Application.ScreenUpdating = False
Columns("A:M").Interior.ColorIndex = xlNone
For J = 10 To Range("M" & Rows.Count).End(xlUp).Row
  If Range("M" & J) >= 60 AND Len(Range("M" & j)) > 0 Then Range("B" & J).Resize(, 12).Interior.ColorIndex = 15
Next J
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

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