Do not colour header row cell

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
817
Hi RichardSchollar

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

Forum statistics

Threads
1,141,720
Messages
5,708,081
Members
421,545
Latest member
TWR

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
Top