Solved

Color Row based on cell value

Posted on 2011-09-08
237 Views
excel 2003
vba routine needed

I need to Loop through all rows
Look in Column A: If a value is  "CS_Project_Number"
Then color that row  "Gray" from  Column A:J

Thanks
fordraiders
0
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 5
• 2

LVL 40

Expert Comment

ID: 36503285
Does this fit your needs?
``````Option Explicit

Sub Q27297739()
With ActiveSheet
If .Cells(1, 1).Value = "CS_Project_Number" Then
With .Columns("A:J").Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
End If
End With
End Sub
``````
0

LVL 40

Expert Comment

ID: 36503299
ColorIndex doesn't have all the colours, but Color can be set using RGB.

``````Option Explicit

Sub Q27297739()
With ActiveSheet
If .Cells(1, 1).Value = "CS_Project_Number" Then
With .Columns("A:J").Interior
.Color = RGB(127, 127, 127)
.Pattern = xlSolid
End With
End If
End With
End Sub
``````
0

LVL 3

Author Comment

ID: 36503390
both solutions color every row  not just the row containing  "CS_Project_Number"

0

LVL 40

Expert Comment

ID: 36503400
Can you give me an example spreadsheet as I've misunderstood your structure.
0

LVL 40

Accepted Solution

Richard Quadling earned 500 total points
ID: 36503463
Is this what you wanted?

``````Option Explicit

Sub Q27297739()
Dim o_Row As Range

For Each o_Row In ActiveSheet.UsedRange.Rows
With o_Row
If .Cells(1, 1).Value = "CS_Project_Number" Then
With .Columns("A:J").Interior
.Color = RGB(255, 127, 127)
.Pattern = xlSolid
End With
Else
.Columns("A:J").Interior.ColorIndex = xlNone
End If
End With
Next o_Row
End Sub
``````
0

LVL 3

Author Closing Comment

ID: 36503504
Perfect Thanks !
0

LVL 40

Expert Comment

ID: 36503561
Sorry it took so long.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.