Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code wont compare negative numbers correctly


I had to format a row of numbers depending on the value above it.


I have to compare A2 to A1 and change A2 accordingly.

Problem is when A1 is a negative number the conditional formattin
doesn't work.

Here is my code: I'm pretty new at this so it is probably really ugly


Dim x
Range("G22").Select
Do While ActiveCell < 0
x = ActiveCell.Offset(-1, 0).Value
'MsgBox x
'MsgBox ActiveCell.Value
If ActiveCell.Value = (x + (x * 0.05)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
ElseIf ActiveCell.Value <= (x - (x * 0.05)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
ElseIf ActiveCell.Value = (x + (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
ElseIf ActiveCell.Value <= (x - (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
ElseIf ActiveCell.Value < (x + (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
ElseIf ActiveCell.Value (x - (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
End If
ActiveCell.Offset(0, 1).Select
Loop
End Su

--
evil bab
-----------------------------------------------------------------------
evil baby's Profile: http://www.excelforum.com/member.php...fo&userid=3198
View this thread: http://www.excelforum.com/showthread.php?threadid=51710

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code wont compare negative numbers correctly


Just bumping this to see if I can get any help

--
evil bab
-----------------------------------------------------------------------
evil baby's Profile: http://www.excelforum.com/member.php...fo&userid=3198
View this thread: http://www.excelforum.com/showthread.php?threadid=51710

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default code wont compare negative numbers correctly

Sub aaTest()
Dim x
Range("G22").Select
Do While ActiveCell < 0
x = ActiveCell.Offset(-1, 0).Value
y = ActiveCell.Value
'MsgBox x
'MsgBox ActiveCell.Value
x = Abs(x)
y = Abs(y)
If y = (x + (x * 0.05)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
ElseIf y <= (x - (x * 0.05)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
ElseIf y = (x + (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
ElseIf y <= (x - (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
ElseIf y < (x + (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
ElseIf y (x - (x * 0.02)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
End If
ActiveCell.Offset(0, 1).Select
Loop
End Sub

--
Regards,
Tom Ogilvy



"evil baby" wrote
in message ...

Just bumping this to see if I can get any help.


--
evil baby
------------------------------------------------------------------------
evil baby's Profile:

http://www.excelforum.com/member.php...o&userid=31983
View this thread: http://www.excelforum.com/showthread...hreadid=517107



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code wont compare negative numbers correctly


Thanks for the help I'll work with that code.


--
evil baby
------------------------------------------------------------------------
evil baby's Profile: http://www.excelforum.com/member.php...o&userid=31983
View this thread: http://www.excelforum.com/showthread...hreadid=517107

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
formula wont copy across to other cells correctly chrissywhittle Excel Discussion (Misc queries) 10 March 9th 06 05:24 AM
Compare Negative & Positive Numbers chom New Users to Excel 3 July 28th 05 08:26 AM
*.csv file wont load correctly Nightwing Excel Discussion (Misc queries) 3 December 1st 04 03:48 PM
VBA: For Each.... wont work correctly / is placement wrong? Mcasteel[_35_] Excel Programming 0 November 10th 04 02:42 AM


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