Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Highlght rows

I have a column containing a collection of various numbers. I need to use
code to highlight the rows containing the number 5.

I have tried with this but it does not work.

For Each Cell In Columns(2)

If Cell.Value = "5" Then
EntireRow.Select

With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If

Not sure why....Help please?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Highlght rows

It's probably not working because your comparison looks for text and
your cells contain numbers.

Try:

Dim rCell As Range
For Each rCell In Range("B1:B" & _
Range("B" & Rows.Count).End(xlUp).Row)
With rCell
If IsNumeric(.Value) Then
If .Value = 5 Then
With .EntireRow.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If
End If
End With
Next rCell

Note that there's no need to select anything.


In article ,
Alan M wrote:

I have a column containing a collection of various numbers. I need to use
code to highlight the rows containing the number 5.

I have tried with this but it does not work.

For Each Cell In Columns(2)

If Cell.Value = "5" Then
EntireRow.Select

With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If

Not sure why....Help please?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Highlght rows

this may work but assumes no blank rows in range you are checking:

For Each rw In Worksheets(1).Cells(1, 1).CurrentRegion.Rows
check = rw.Cells(1, 2).Value
If check = 5 Then rw.EntireRow.Interior.ColorIndex = 15
Next
--
JB


"Alan M" wrote:

I have a column containing a collection of various numbers. I need to use
code to highlight the rows containing the number 5.

I have tried with this but it does not work.

For Each Cell In Columns(2)

If Cell.Value = "5" Then
EntireRow.Select

With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If

Not sure why....Help please?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Highlght rows

sub colorrows()
mc=2
for i=1 to cells(rows.count,mc).end(xlup).row
if cells(i,mc)=5 then rows(i).interior.colorindex=15
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Alan M" wrote in message
...
I have a column containing a collection of various numbers. I need to use
code to highlight the rows containing the number 5.

I have tried with this but it does not work.

For Each Cell In Columns(2)

If Cell.Value = "5" Then
EntireRow.Select

With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If

Not sure why....Help please?


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
Enabling option „Format rows“ to hide/unhide rows using VBA-code? ran58 Excel Discussion (Misc queries) 0 July 28th 09 03:46 PM
Counting characters in multiple rows when rows meet specific criteria news.virginmedia.com Excel Worksheet Functions 3 June 28th 08 09:03 PM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Excel Programming 1 November 16th 07 10:41 PM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Excel Programming 2 August 1st 07 02:02 AM
Excel 2003 -Rows hidden. Scrolling unhides rows ! How do I stop th Excellent1975 Excel Discussion (Misc queries) 0 June 21st 06 08:01 PM


All times are GMT +1. The time now is 02:37 AM.

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

About Us

"It's about Microsoft Excel"