Hi kwoznica,
There should be no need to use VBA for this. Use Conditional Formatting instead -> http://www.cpearson.com/ex
Regards,
Wayne
Main Topics
Browse All TopicsI would like to create an excel macro which highlights an entire row to red based on a condition within a cell. What is the best way to go about doing this procedure? Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi kwoznica,
There should be no need to use VBA for this. Use Conditional Formatting instead -> http://www.cpearson.com/ex
Regards,
Wayne
I would use conditional formatting rather than a macro for this. Say you want the row highlighted if column A = 5, you would do the following:
1. Select the columns you want highlighted
2. Choose Format-Conditional formatting from the menu
3. Change the dropdown to FormulaIs and enter =$A1=5 in the formula box.
4. Press the Format... button and choose the pattern you want.
5. OK out of the dialog.
Regards,
Rory
In this case, conditional formatting wont work, as it only colors the cell which contains the value, and not the entire row.
Here is a macro that will color the entire row:
Sub Color_Only()
''''''''''''''''''''''''''
' Copyright (C) Irial 2007 '
'Feel free to use this macro as a reference for other macros'
''''''''''''''''''''''''''
ASUP = Application.ScreenUpdating
Application.ScreenUpdating
Range("A1:A999").Select
Application.CutCopyMode = False
For Each cell In Range("A:A")
If cell.Value = 1 Then
Range(cell.Row & ":" & cell.Row).Interior.ColorIn
End If
Next
Application.ScreenUpdating
End Sub
How to use this macro:
The macro select the cells in the range you tell it to. (Range A1:A999) and checks each and every cell in that range against a value. In my case, it will check each cell to determine id the value is 1. If it finds that particular value, it will color the entire row of that cell red. If it does not find anything, it will leave the row alone.
I hope this helps, and with kind regards,
~Irial
Hiyas Rory,
In all due honesty, i completely missed your comment.
Your method does indeed work, but i would not want to use this method if i had 1000, or even 100 lines i needed to color. You would have to fill in the formula for each of those lines in the dialog box, which is quite a hassle if you ask me. Also, by default the amount of conditional formats is limited to 3. If you have 100 lines, how would you color them? And even if there was a workaround for that, would you be writing coditional formats on a 1-1 ratio with the amount of lines in the file? Or am i perhaps missing some excel functionality that allows easy execution of these tasks? :)
With kind regards as ever,
~Irial
Here is the macro for that:
Sub Color_Only()
''''''''''''''''''''''''''
' Copyright (C) Irial 2007 '
'Feel free to use this macro as a reference for other macros'
''''''''''''''''''''''''''
ASUP = Application.ScreenUpdating
Application.ScreenUpdating
Range("F1:F999").Select
Application.CutCopyMode = False
For Each cell In Range("F:F")
If cell.Formula = "Pending" Then
Range(cell.Row & ":" & cell.Row).Interior.ColorIn
End If
Next
Application.ScreenUpdating
End Sub
Here is a little explanation:
>> For Each cell In Range("F:F") <<
This little piece of code will check each cell in the range you enter for a certain value. If you set it to F:F such as in this case, it will check the cells in the F column. Settings it to A:A will logically check the cells in that column. You can set it to any range you like, even to multiple columns if you want.
>> If cell.Formula = "Pending" Then <<
This will check if the value of the cell is "Pending". Set it to anything you want to find.
>> Range(cell.Row & ":" & cell.Row).Interior.ColorIn
This will select the entire row, and set its color to red. If you want a different color, change the number on the end.
With kind regards,
~Irial
Here's a conditional formatting example: http://www.ee-stuff.com/Ex
If you enter Pending into a cell in column F, columns A to K for that row will be highlighted in blue. (You could make the entire row highlight if you want)
Regards,
Rory
You ask for a macro which is as follows but if you can I recommend you accept a conditional formatting suggestion i.e. the first post.
Sub Color_Row()
Dim bol_screen As Boolean
Dim cell As Range
bol_screen = Application.ScreenUpdating
Application.ScreenUpdating
For Each cell In Range("F:F")
' For Each cell In Range("F1:F100")
If cell.Formula = "Pending" Then
cell.EntireRow.Interior.Co
Else
cell.EntireRow.Interior.Co
End If
Next
Application.ScreenUpdating
End Sub
Business Accounts
Answer for Membership
by: jellPosted on 2007-09-26 at 06:54:55ID: 19963027
Select the entire row.
Click Format -> Conditional formatting
Select 'Formula Is' from the drop down.
Copy & Paste this into the condition: -
=$A$1="Red"
Where $A$1 is the cell that your testing, and "Red" is the condition. You can then select what format you want from the format button.
Ta
Jell