Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Calculation Problem

I am using the worksheet_change event (EXCEL 97) to make
sure that the user types in numbers to no more than the
hundredths decimal place. If they type in a number like:

4.57 - entry is OK
4.572 - entry is bad

If the entry is bad I change the font to bold.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If Int(.Value * 100) < .Value * 100 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End With
End Sub

The code appears to work for most cases, but for certain
numbers like 2.32 and 4.56 it turns the values bold (even
though it should not). I am going NUTZ. Help would be
much appreciated...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Calculation Problem

It sounds like a binary conversion problem. You could try using the Len and
InStr functions to determine how many numbers there are after the decimal.

HTH, Greg

"Derek" wrote in message
...
I am using the worksheet_change event (EXCEL 97) to make
sure that the user types in numbers to no more than the
hundredths decimal place. If they type in a number like:

4.57 - entry is OK
4.572 - entry is bad

If the entry is bad I change the font to bold.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If Int(.Value * 100) < .Value * 100 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End With
End Sub

The code appears to work for most cases, but for certain
numbers like 2.32 and 4.56 it turns the values bold (even
though it should not). I am going NUTZ. Help would be
much appreciated...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calculation Problem

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
if Instr(.Value,".") = 0 then
.FontBold = False
else
If len(.value)-instr(.Value,".") 2 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End if
End With
End Sub


--
Regards,
Tom Ogilvy

Derek wrote in message
...
I am using the worksheet_change event (EXCEL 97) to make
sure that the user types in numbers to no more than the
hundredths decimal place. If they type in a number like:

4.57 - entry is OK
4.572 - entry is bad

If the entry is bad I change the font to bold.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If Int(.Value * 100) < .Value * 100 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End With
End Sub

The code appears to work for most cases, but for certain
numbers like 2.32 and 4.56 it turns the values bold (even
though it should not). I am going NUTZ. Help would be
much appreciated...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Calculation Problem

Your solution seems to work nicely. I was also able to
correct the problem by comparing strings instead of
numbers. Was there a flaw in my original logic, or is do
you think it is just a bug in Excel 97? When I stepped
through the code I was getting 2.32 x 100 = 231 (instead
of the expected 232). Thanks for your help.
-----Original Message-----
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
if Instr(.Value,".") = 0 then
.FontBold = False
else
If len(.value)-instr(.Value,".") 2 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End if
End With
End Sub


--
Regards,
Tom Ogilvy

Derek wrote in message
...
I am using the worksheet_change event (EXCEL 97) to make
sure that the user types in numbers to no more than the
hundredths decimal place. If they type in a number

like:

4.57 - entry is OK
4.572 - entry is bad

If the entry is bad I change the font to bold.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As

Excel.Range)
With Target
If Int(.Value * 100) < .Value * 100 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End With
End Sub

The code appears to work for most cases, but for certain
numbers like 2.32 and 4.56 it turns the values bold

(even
though it should not). I am going NUTZ. Help would be
much appreciated...



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Calculation Problem

I believe it has to do with the way computers store floating point numbers.

Just like you can't precisely represent 1/3 as a decimal number, many
numbers can not be represented exactly in binary. Since you truncate the
number, if it is slightly less that 2.32 (2.3199999999999), you get 231.

--
Regards,
Tom Ogilvy

Derek wrote in message
...
Your solution seems to work nicely. I was also able to
correct the problem by comparing strings instead of
numbers. Was there a flaw in my original logic, or is do
you think it is just a bug in Excel 97? When I stepped
through the code I was getting 2.32 x 100 = 231 (instead
of the expected 232). Thanks for your help.
-----Original Message-----
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
if Instr(.Value,".") = 0 then
.FontBold = False
else
If len(.value)-instr(.Value,".") 2 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End if
End With
End Sub


--
Regards,
Tom Ogilvy

Derek wrote in message
...
I am using the worksheet_change event (EXCEL 97) to make
sure that the user types in numbers to no more than the
hundredths decimal place. If they type in a number

like:

4.57 - entry is OK
4.572 - entry is bad

If the entry is bad I change the font to bold.

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As

Excel.Range)
With Target
If Int(.Value * 100) < .Value * 100 Then
.Font.Bold = True
Else
.Font.Bold = False
End If
End With
End Sub

The code appears to work for most cases, but for certain
numbers like 2.32 and 4.56 it turns the values bold

(even
though it should not). I am going NUTZ. Help would be
much appreciated...



.



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
calculation problem Suleman[_2_] Excel Worksheet Functions 3 April 28th 08 04:11 AM
Calculation Problem slwaite Excel Discussion (Misc queries) 1 July 18th 06 07:31 PM
calculation problem les Excel Discussion (Misc queries) 1 November 24th 05 11:33 AM
Calculation Problem dave Excel Discussion (Misc queries) 0 August 24th 05 03:15 PM
Calculation Problem cvolkert Excel Discussion (Misc queries) 0 August 22nd 05 06:14 PM


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