VBA Areas Highlight that do not have certain values in them

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,177
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good afternoon,
Please see data below. I am looking for some VBA code that will highlight an area if it does not have a value in it.
In Column E if the first 2 Alpha characters do not start with "MA" or "EN" then highlight the area, if not leave blank.
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
<table class="tableizer-table">
<thead><tr class="tableizer-firstrow"><th>ID</th><th>Name</th><th>Year</th><th>School</th><th>Course</th></tr></thead><tbody>
<tr><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>7777777</td><td>xxxxxxx</td><td>17-18</td><td>111</td><td>AD012YPLGE</td></tr>
<tr><td>7777777</td><td>xxxxxxx</td><td>17-18</td><td>111</td><td>SC215YMAMA</td></tr>
<tr><td>7777777</td><td>xxxxxxx</td><td>17-18</td><td>111</td><td>MA301YTDCL</td></tr>
<tr><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>8888888</td><td>yyyyyyy</td><td>17-18</td><td>222</td><td>CS121YMAMA</td></tr>
<tr><td>8888888</td><td>yyyyyyy</td><td>17-18</td><td>222</td><td>EN401YMAMA</td></tr>
<tr><td>8888888</td><td>yyyyyyy</td><td>17-18</td><td>222</td><td>PE100YTDGE</td></tr>
<tr><td>8888888</td><td>yyyyyyy</td><td>17-18</td><td>222</td><td>AD012YPLGE</td></tr>
<tr><td>8888888</td><td>yyyyyyy</td><td>17-18</td><td>222</td><td>AD014YPLGE</td></tr>
<tr><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr bgcolor="#FF0000"><td>9999999</td><td>zzzzzzz</td><td>17-18</td><td>333</td><td>ID102YTDAP</td></tr>
<tr bgcolor="#FF0000"><td>9999999</td><td>zzzzzzz</td><td>17-18</td><td>333</td><td>WL103YMAMA</td></tr>
<tr bgcolor="#FF0000"><td>9999999</td><td>zzzzzzz</td><td>17-18</td><td>333</td><td>PE100YTDGE</td></tr>
<tr bgcolor="#FF0000"><td>9999999</td><td>zzzzzzz</td><td>17-18</td><td>333</td><td>SC420YMAMA</td></tr>
<tr bgcolor="#FF0000"><td>9999999</td><td>zzzzzzz</td><td>17-18</td><td>333</td><td>AD011YPLGE</td></tr>
</tbody></table>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
Code:
Sub Hilite()
   Dim Rng As Range
   Dim i As Long
   
   For Each Rng In ActiveSheet.UsedRange.Offset(1).SpecialCells(xlConstants).Areas
      For i = 1 To Rng.Rows.Count
         If Left(Rng.Cells(i, 5), 2) = "MA" Or Left(Rng.Cells(i, 5), 2) = "EN" Then
            Exit For
         ElseIf i = Rng.Rows.Count Then
            Rng.Interior.Color = vbRed
         End If
      Next i
   Next Rng
End Sub
 
Upvote 0
Thank you very much Fluff! Much appreciated! Works perfectly! Have a great weekend!
 
Upvote 0
Glad to help & thanks for the feedback.

Have a good weekend yourself.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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