Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

code wont compare negative numbers correctly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
evil baby - 28 Feb 2006 03:16 GMT
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 baby - 28 Feb 2006 16:40 GMT
Just bumping this to see if I can get any help
Tom Ogilvy - 28 Feb 2006 18:20 GMT
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

Signature

Regards,
Tom Ogilvy

> Just bumping this to see if I can get any help.
evil baby - 28 Feb 2006 18:31 GMT
Thanks for the help I'll work with that code.

Signature

evil baby

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.