Do not colour header row cell

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
833
Hi all

The code below checks to see if there is a value in column 1 and if true checks to see if the value in column 4 is (A through J). If not then it colours the cell in column 4 with a red background.

The problem I have is that I have a header row. The code highlights cells that do not meet the criteria which will always include Cell D1 . I dont want this to happen. Row 1 is a header row and I need the code to omit row 1. Any assistance with code amendment to exclude row 1 would be great.

Code:
Sub Error_checker()
For Each c In ActiveSheet.UsedRange.Columns(1).Cells
   If Not IsEmpty(c) Then
       If IsError(Application.Search(c.Offset(0, 3).Value, "ABCDEFGHIJ")) _
        Or IsEmpty(c.Offset(0, 3)) Then
           c.Offset(0, 3).Interior.ColorIndex = 3
       End If
   End If
Next c
Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Jak

If row(1) should never be included, then maybe you should set the range differently:

Code:
Set Rng = ActiveSheet.UsedRange.Offset(1,0).Resize(Activesheet.UsedRange.Rows.Count-1).Columns(1).Cells

...
For Each c In Rng
...

Alternatively, you could test the row value of c to check if it's 1 (in which case skip over).

Best regards


Richard
 
Upvote 0
Hi RichardSchollar

Many thanks for a quick response and solution. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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