ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "For Each" statements (https://www.excelbanter.com/excel-programming/373827-each-statements.html)

MGSurberDallas

"For Each" statements
 
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael

PCLIVE

"For Each" statements
 
This should get you started.

For Each cell In Range("F1:F65536")
If cell.Value = "X" _
Then
cell.EntireRow.Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else:
End If
Next cell


This changes the background color of the entire row to yellow if the value
of the cell in column F is "X". Modify as necessary.

HTH,
Paul

"MGSurberDallas" wrote in message
...
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael




Ronald Dodge

"For Each" statements
 
Dim I as Long, lngFRow as Long, lngLRow as Long, wshList as Worksheet

Set wshList = Workbooks("Book1.xls").Worksheets("Sheet1") 'Sets the variable
to a reference of the worksheet you want to manipulate
lngFRow = 5 'The first row number you want to check for highlighting
lngLRow = 2000 'The last row number you want to check for highlighting
For I = lngFRow to lngLRow Step 1
If wshList.Range("F" & CStr(I)).Value = 50 Then 'Checks to see if the F
column contains a numeric value of 50
wshList.Range(CStr(I) & ":" & CStr(I)).Interior.ColorIndex = 8 'Cyan
background color if the value of that row in the F column is 50
Else
wshList.Range(CStr(I) & ":" & CStr(I)).Interior.ColorIndex =
xlColorIndexNone 'No background color otherwise
EndIf
Next I

--
Ronald R. Dodge, Jr.
Production Statistician/Programmer
Master MOUS 2000

"MGSurberDallas" wrote in message
...
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael




Bob Phillips

"For Each" statements
 
Use conditional formatting.

See http://www.contextures.com/xlCondFormat01.html

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"MGSurberDallas" wrote in message
...
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael




MGSurberDallas

"For Each" statements
 
Thanks Ron. I'll give it a shot!

Michael

"Ronald Dodge" wrote:

Dim I as Long, lngFRow as Long, lngLRow as Long, wshList as Worksheet

Set wshList = Workbooks("Book1.xls").Worksheets("Sheet1") 'Sets the variable
to a reference of the worksheet you want to manipulate
lngFRow = 5 'The first row number you want to check for highlighting
lngLRow = 2000 'The last row number you want to check for highlighting
For I = lngFRow to lngLRow Step 1
If wshList.Range("F" & CStr(I)).Value = 50 Then 'Checks to see if the F
column contains a numeric value of 50
wshList.Range(CStr(I) & ":" & CStr(I)).Interior.ColorIndex = 8 'Cyan
background color if the value of that row in the F column is 50
Else
wshList.Range(CStr(I) & ":" & CStr(I)).Interior.ColorIndex =
xlColorIndexNone 'No background color otherwise
EndIf
Next I

--
Ronald R. Dodge, Jr.
Production Statistician/Programmer
Master MOUS 2000

"MGSurberDallas" wrote in message
...
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael





MGSurberDallas

"For Each" statements
 
Thank you SO much Paul. It worked like a charm.

Best Regards,

Michael

"PCLIVE" wrote:

This should get you started.

For Each cell In Range("F1:F65536")
If cell.Value = "X" _
Then
cell.EntireRow.Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else:
End If
Next cell


This changes the background color of the entire row to yellow if the value
of the cell in column F is "X". Modify as necessary.

HTH,
Paul

"MGSurberDallas" wrote in message
...
I am relatively new to programming. Can anyone suggest the code for the
following:

I want to highlight each row that contains a certain value in a particular
column.

For Each Row that contains X in Cell F
then highlight row.

Can anyone get me started? Thanks Michael






All times are GMT +1. The time now is 11:12 AM.

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