View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter Rooney Peter Rooney is offline
external usenet poster
 
Posts: 325
Default Percentage difference between numbers in 2 cells

Rajagopal,

Sorry, I only did +5% - I forgot -5% !

Private Sub worksheet_change(ByVal Target As Range)

Dim CheckRange As Range
Dim CheckCell As Range

Set CheckRange = ActiveSheet.Range("CheckRange") 'this could be e.g.
range("A1:A15")

For Each CheckCell In CheckRange
CheckCell.Offset(-1, 0).Address & " " & CheckCell.Offset(-1, 0).Value)
If CheckCell.Row CheckRange.Cells(1).Row Then 'don't check the
first cell in the range
If CheckCell.Value = (CheckCell.Offset(-1, 0).Value * 1.05) Or _
CheckCell.Value <= (CheckCell.Offset(-1, 0).Value * 0.95) Then

CheckCell.Font.ColorIndex = 3
Else
CheckCell.Font.ColorIndex = 1
End If
End If
Next

End Sub


"Rajagopal" wrote:

Hi,

I have an excel sheet where I need to mark the rows in red colour if
the value in the current row is + or - 5% the previous row. Please suggest me
How I can do it.

Regards,
Rajagopal