Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Change row color based on cell value in Excel 2007 VBA

Posted on 2011-10-05
3
Medium Priority
?
400 Views
Last Modified: 2012-05-12
Hi all.

I have the code below that changes the color of a cell if it equals "SHEET". But I want to take it to the next level by highlighting the row from Column A to Column E. How can I do this?

Thank you in advance!
Dim rng2 As Long

With Worksheets("Sheet1")

    rng2 = .Range("A" & Rows.Count).End(xlUp).Row
    
 
    .Range("I3:I" & rng2).NumberFormat = "$ 0.0000"
    .Range("D3:D" & rng2).Columns.AutoFit
    .Range("J3:J" & rng2).Columns.AutoFit
    .Range("K3:K" & rng2).Columns.AutoFit
    .Range("L3:L" & rng2).Columns.AutoFit
    
    Set MR = Range("J3:J" & rng2)
    
    For Each cell In MR
        
        If cell.Value = "SHEET" Or cell.Value = "Sheet" Then cell.Interior.ColorIndex = 36
    
    Next

End With

Open in new window

0
Comment
Question by:printmedia
  • 2
3 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 36919200
Try this

For Each cell In MR
        
        If cell.Value = "SHEET" Or cell.Value = "Sheet" Then cell.offset(,-9).resize(,5).Interior.ColorIndex = 36
    
    Next

Open in new window

0
 
LVL 24

Accepted Solution

by:
StephenJR earned 2000 total points
ID: 36919212
Or fractionally shorter:
For Each cell In MR
    If UCase(cell.Value) = "SHEET" Then cell.Offset(, -9).Resize(, 5).Interior.ColorIndex = 36
Next

Open in new window

0
 

Author Closing Comment

by:printmedia
ID: 36919242
Thanks again Stephen! I'll be posting some more questions.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

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

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

Join & Ask a Question