Yes it varies too. and for each Test X the color should be different.
Test 1 red,
test 2 blue
test 3 green
and thee 3 test conditions repeat in the sheet. Both rows and columns
are not constant.
Thanks.
Harsh
Try this out and see if it does what you want. Paste all the following
code into a regular module. Run this code when the sheet that has all the
Test data is the active sheet. If you wish, send me an email and I'll send
you the small file I used to develop this code. My email address is
ottokmnop@comcast.net. Remove the "nop" from this address. HTH Otto
Option Explicit
Dim RngColB As Range, First As Range, Last As Range
Dim RngToColor As Range, i As Range, LastRow As Long
Dim c As Long, ColorNum As Long
Sub ColorTests()
Call FindFirstTest
Call ColorData
End Sub
Sub FindFirstTest()
'Find first instance of "Test"
Set RngColB = Range("B2", Range("B" & Rows.Count).End(xlUp))
LastRow = RngColB(RngColB.Count).Row
Set First = RngColB.Find(What:="Test", _
After:=RngColB(RngColB.Count), _
LookAt:=xlPart, SearchOrder:=xlByColumns)
End Sub
Sub ColorData()
Do
'In case of no data after First
If Left(First.Offset(1), 4) = "Test" Then
Set First = First.Offset(1)
GoTo LoopAgain
End If
Call GetLast
Select Case Right(First, 1)
Case "1": ColorNum = 3
Case "2": ColorNum = 5
Case "3": ColorNum = 4
End Select
Set RngToColor = Range(First.Offset(1), Last)
For Each i In RngToColor
Range(i, Cells(i.Row, Columns.Count).End(xlToLeft)) _
.Interior.ColorIndex = ColorNum
Next i
Set First = Last.Offset(1)
LoopAgain:
Loop Until Last.Row >= LastRow
End Sub
Sub GetLast()
For c = 2 To 1000
If Left(First.Offset(c), 4) = "Test" Then
Set Last = First.Offset(c - 1)
Exit For
Else
If IsEmpty(First.Offset(c).Value) Then
Set Last = First.Offset(c - 1)
Exit For
End If
End If
Next c
End Sub
> Yes it varies too. and for each Test X the color should be different.
>
[quoted text clipped - 77 lines]
>> >> >> > Thank you,
>> >> >> > Harsh