Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Strange Macro name problem | Excel Discussion (Misc queries) | |||
strange problem | Excel Discussion (Misc queries) | |||
Subtotal problem. Very strange! | Excel Worksheet Functions | |||
Strange Problem | Excel Discussion (Misc queries) | |||
Strange Problem... | Excel Discussion (Misc queries) |