Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Percentage difference between numbers in 2 cells

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Percentage difference between numbers in 2 cells

Rajagopal

You could try pasting this event code into the code window for the worksheet
where you want to do the checking (NOT a normal code module)

Private Sub worksheet_change(ByVal Target As Range)

Dim CheckRange As Range
Dim CheckCell As Range

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

For Each CheckCell In CheckRange
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) Then
CheckCell.Font.ColorIndex = 3
Else
CheckCell.Font.ColorIndex = 1
End If
End If
Next

End Sub

Hope this helps

Pete



"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


  #3   Report Post  
Posted to microsoft.public.excel.programming
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Percentage difference between numbers in 2 cells


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


What about conditional formatting? That would be pretty straight
forward, using something like "=$A1*0,95" as the condition for the
lower bound if you start your values on the first row in the first
column. Just select all the rows you want it to work on (row 2 and
down)...

Depending on exactly what you want you can use 'between' adding a
"=$A1*1,05", or adding the "=$A1*1,05" as an additional condition.
(Using ',' as decimal separator, might be '.' for you.)

/impslayer, aka Birger Johansson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Percentage difference between numbers in 2 cells

Hi, Birger,

I see where you're coming from, but I've never been able to use formulae in
conditional formatting - I don't understand how you set the relative formula
to say ("if the cell above is...")

Typical, I can do it in VBA, but normal Excel - something wrong there, I
think..! :-)

Pete



"impslayer" wrote:


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


What about conditional formatting? That would be pretty straight
forward, using something like "=$A1*0,95" as the condition for the
lower bound if you start your values on the first row in the first
column. Just select all the rows you want it to work on (row 2 and
down)...

Depending on exactly what you want you can use 'between' adding a
"=$A1*1,05", or adding the "=$A1*1,05" as an additional condition.
(Using ',' as decimal separator, might be '.' for you.)

/impslayer, aka Birger Johansson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Percentage difference between numbers in 2 cells


Peter Rooney skrev:

Hi, Birger,

I see where you're coming from, but I've never been able to use formulae in
conditional formatting - I don't understand how you set the relative formula
to say ("if the cell above is...")

Typical, I can do it in VBA, but normal Excel - something wrong there, I
think..! :-)

Pete


Pete,

I actually just did a quick test to see if it worked, and it indeed
seemed to work :)

Normally the formula is like "=$A$1*0,95", but you can remove the "$"s
to make it a relative reference which seems to work perfectly even when
adding the additional formatting to several cells (starting from A2,
which will make the above (but relative) formula mean 'the row
before')!

Best regards,

/impslayer, aka Birger Johansson

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
Difference between three numbers in percentage Jessica Excel Discussion (Misc queries) 7 April 2nd 23 07:49 PM
difference in numbers displayed as a +/- percentage womblew Excel Worksheet Functions 3 October 9th 09 11:14 AM
raising multiple cells containing numbers by a percentage Tammy Dean[_2_] Excel Discussion (Misc queries) 3 July 11th 08 02:48 PM
Finding the percentage difference of two or more numbers slr Excel Worksheet Functions 5 January 26th 06 02:00 PM
percentage difference cimarron trucking New Users to Excel 3 December 8th 04 07:17 PM


All times are GMT +1. The time now is 10:59 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"