ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Highlight row given certain conditions (https://www.excelbanter.com/excel-worksheet-functions/16872-highlight-row-given-certain-conditions.html)

Toby0924

Highlight row given certain conditions
 
Hello!

I am attempting to make a macro that will select a range and look in column
B for an "X" If that condition is met, I would like it to highlight the
entire row, or if it would be easier, to highlight the row in columns A - M.
I have worked on the macro below and I can get the cells with "X" in the
column to hightlight, but I cannot get it to select the entire row.

If there is an easier way to accomplish this I would welcome the
suggestion...this is what I'm currently using.

Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Cell As Range

For Each Cell In Selection
If Cell.Value = "x" Then
Cell.Interior.Color = vbGreen
Else
End If
Next Cell
End Sub

Thanks in advance for you help!

Don Guillett

try
Sub colorrowif()
For Each c In Range("b4:b" & Range("b4").End(xlDown).Row)
If c = "x" Then c.EntireRow.Interior.Color = vbGreen
Next
End Sub

--
Don Guillett
SalesAid Software

"Toby0924" wrote in message
...
Hello!

I am attempting to make a macro that will select a range and look in

column
B for an "X" If that condition is met, I would like it to highlight the
entire row, or if it would be easier, to highlight the row in columns A -

M.
I have worked on the macro below and I can get the cells with "X" in the
column to hightlight, but I cannot get it to select the entire row.

If there is an easier way to accomplish this I would welcome the
suggestion...this is what I'm currently using.

Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Cell As Range

For Each Cell In Selection
If Cell.Value = "x" Then
Cell.Interior.Color = vbGreen
Else
End If
Next Cell
End Sub

Thanks in advance for you help!




Bob Umlas, Excel MVP

First, you don't need a macro at all, you can use conditional formatting.
Select A:M and then use format/conditional formatting, change "Cell Value is"
to Formula Is", and enter this (assuming A1 is the active cell):
=$B1="X"
Then click the Format button and select the patterns tab, select the green
you want.

HTH
Bob Umlas
Excel MVP

"Toby0924" wrote:

Hello!

I am attempting to make a macro that will select a range and look in column
B for an "X" If that condition is met, I would like it to highlight the
entire row, or if it would be easier, to highlight the row in columns A - M.
I have worked on the macro below and I can get the cells with "X" in the
column to hightlight, but I cannot get it to select the entire row.

If there is an easier way to accomplish this I would welcome the
suggestion...this is what I'm currently using.

Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Cell As Range

For Each Cell In Selection
If Cell.Value = "x" Then
Cell.Interior.Color = vbGreen
Else
End If
Next Cell
End Sub

Thanks in advance for you help!


Toby0924

Thank you so much for your help!!!!

"Toby0924" wrote:

Hello!

I am attempting to make a macro that will select a range and look in column
B for an "X" If that condition is met, I would like it to highlight the
entire row, or if it would be easier, to highlight the row in columns A - M.
I have worked on the macro below and I can get the cells with "X" in the
column to hightlight, but I cannot get it to select the entire row.

If there is an easier way to accomplish this I would welcome the
suggestion...this is what I'm currently using.

Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Dim Cell As Range

For Each Cell In Selection
If Cell.Value = "x" Then
Cell.Interior.Color = vbGreen
Else
End If
Next Cell
End Sub

Thanks in advance for you help!



All times are GMT +1. The time now is 06:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com