How can I color every other row but skip any row where Column A = X?
Whats wrong is it colors over my sub heading rows. I am trying to get it to skip the heading rows which is marked by an invisible X in Column A.
Can it skip the sub headings and the row below the sub heading row be white? Kind of like its starting over again.
This is the code I have that colors rows white then gray to the end for the entire range:
Sub Format()
Application.ScreenUpdating = False
Dim sht2 As Worksheet
Set sht2 = ThisWorkbook.Worksheets("Email Form")
sht2.Activate
sht2.Unprotect
Dim LastRow As Long, LastCol As Long
Dim rng As Range
Dim WholeRng As Range
With sht2
Set rng = Cells
LastRow = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
LastCol = rng.Find(What:="*", After:=rng.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
Set WholeRng = Range(Cells(4, "B"), Cells(LastRow, LastCol))
WholeRng.Select
With WholeRng
With .Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 255, 255)
.TintAndShade = 0
Range(Cells(4, "B"), Cells(LastRow, LastCol)).Borders(xlInsideHorizontal).LineStyle = xlContinuous
Range(Cells(4, "B"), Cells(LastRow, LastCol)).Borders(xlInsideVertical).LineStyle = xlContinuous
Range(Cells(4, "B"), Cells(LastRow, LastCol)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Range(Cells(4, "B"), Cells(LastRow, LastCol)).Borders(xlEdgeRight).LineStyle = xlContinuous
End With
End With
Dim b As Boolean
For Each rng In WholeRng.Rows
If Not rng.Hidden Then
If b Then rng.Interior.Color = Black
b = Not b
End If
Next
End With
Set rng = Nothing
Set WholeRng = Nothing
Set sht2 = Nothing
Application.ScreenUpdating = True
End Sub
LastRow,LastColvariable could hold nothing if the sheet is blank and theWholeRngwill throw an error as a result. TheWholeRng.Selectline isn't needed - you'll colour the interior without it being selected. You might also want toresizeyourWholeRngto add borders rather than use theLastRow,LastColon theActiveSheet(you haven't qualified the sheet name with your range references). - Darren Bartrup-Cook=Offset(here,1-Column,0) == "x"=> this would look for every cell, go1-Columnto the right (orColumn - 1to the left, ending up in columnA), and then check if the value equals"x". Just one problem: does anybody know how to fill in the first argument ofOffset()formula? How to say : "Offset from this cell onwards"? - Dominique