View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
amanda amanda is offline
external usenet poster
 
Posts: 12
Default compare cell valeus and highlight row

On Jul 26, 10:10 pm, OssieMac
wrote:
Hi Amanda,

The following macro should put a fill color of yellow on all the rows where
value in column A is = 3 and value in corresponding row in column F is zero.

Sub Compare_Cells()

Dim rnge1 As Range
Dim c1 As Range

'Find the last cell with data in column A.
'and name range from cell A1 to last cell with data.
Set rnge1 = Sheets("Sheet1").Range("A1", Cells(Rows.Count, 1) _
.End(xlUp))

'Loop through each cell in range
For Each c1 In rnge1

'Test value of c1 and value of cell in column F
If c1.Value = 3 And c1.Offset(0, 5) = 0 Then

Rows(c1.Row).Interior.Color = 65535

End If

Next c1

End Sub

I will appreciate it if you let me know if it works.

Regards,

OssieMac



"amanda" wrote:
I would like to highlight a row in excel using a macro that would
compare the cell value in one colum to the cell value in another
column in the same row. Specifically, if the cell value in column A
is 3 or greater and the cell value in column F is 0 I want this row to
stand out. Any ideas?- Hide quoted text -


- Show quoted text -


Hi there, thanks for the response!

A couple of qualifiers. The colums I'm trying to compare are colums C
and F both of which contain perctentages. So, if the cell value of C
= 3% or greater AND the cell value of data in column F = 0% then
highlight. I tried changing the column to C but I think I'm not
getting something as I am getting a syntax error in the 6th line
starting with "Set rnge1 =....".

Thanks!!