Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default "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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default "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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default "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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default "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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default "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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default "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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Need more than 7 nested "IF" statements in Excel" James A Excel Discussion (Misc queries) 1 December 17th 06 02:02 AM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 04:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"