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

Hi Stuart,

You're running into issues caused by floating point calculations (from the
multiplication operations). To avoid issues, you could try something like
this:

Sub GreaterThan2DecPlaces()
Dim rng As Range
Dim sNum As String

For Each rng In Selection.Cells
If Abs(rng.Value - Round(rng.Value, 2)) Then
Debug.Print rng.Address
End If
Next rng
End Sub

--
Regards,

Jake Marx
www.longhead.com


Stuart wrote:
I have used the following block of code to try and detect any number
that is more than two decimal places in length, unfortunately I am
getting strange results, occasionally it is throwing out numbers that
are correct. the differance being a very small amount such as
1.42145*10^-14

Why is it doing this?....and is there a more reliable way of detecting
numbers over two decimal places in length?


For Each num In Selection
If Int(num * 100) - (num * 100) < 0 Then
MsgBox "More then two decimal places....."
MsgBox Int(num * 100) - (num * 100)
End If
Next num


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Strange problem

I have used the following block of code to try and detect any number that is
more than two decimal places in length, unfortunately I am getting strange
results, occasionally it is throwing out numbers that are correct. the
differance being a very small amount such as 1.42145*10^-14

Why is it doing this?....and is there a more reliable way of detecting
numbers over two decimal places in length?


For Each num In Selection
If Int(num * 100) - (num * 100) < 0 Then
MsgBox "More then two decimal places....."
MsgBox Int(num * 100) - (num * 100)
End If
Next num



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
Strange Macro name problem Joe M. Excel Discussion (Misc queries) 2 January 26th 10 12:41 AM
strange problem -Bryan[_2_] Excel Discussion (Misc queries) 3 May 1st 08 06:56 PM
Subtotal problem. Very strange! Carl Excel Worksheet Functions 0 October 6th 06 04:07 PM
Strange Problem Perry Excel Discussion (Misc queries) 7 April 12th 06 09:52 PM
Strange Problem... Sujesh Excel Discussion (Misc queries) 6 December 30th 05 02:56 PM


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