Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default using decimal numbers in for-next statement

Just another option in the immediate window (use of @)

For i = 2 To 3 Step 0.01@: Debug.Print i: Next i

'or

Sub Demo()
Dim i As Currency
For i = 2 To 3 Step 0.01: Debug.Print i: Next i
End Sub

Dana

"Tushar Mehta" wrote in message
news:MPG.1b82ad57e64d231d9898b9@news-server...
Tom's comment about precision loss in cells also applies to VBA. Try
this simple test. In the Immediate Window type in

for i=2.00 to 3.00 step 0.01:debug.Print i:next i

Upto 2.23 everything is as expected. Then, instead of 2.24, I get
2.23999999999999. By contrast, the following gave accurate results
from 2 to 3:

For xStep=0 to (3-2)/0.01:x=2+xStep*0.01:debug.Print x:next xstep

So, you may want to try:

dim xStep as integer,x as double
'might need long rather than integer
For xStep=0 to (gb-ga)/0.01
x=ga+xStep*0.01
...
next xStep

Also, when you share code, it would help if you included the variable
declaration statements.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , Peer
says...
I have tried every datatype it could possibly be;

integer, long, single, double, even variant after which I defined
decimal numbers with cdec.

It was the first solution (or error) I thought of.

And the numbers are exactly the numbers I'm searching for, beause there
are no formula's in the range, and the values are manual input.




---
Message posted from http://www.ExcelForum.com/




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
Decimal Numbers typed into Excel 2003 read as whole numbers john mcmichael Excel Discussion (Misc queries) 1 May 10th 07 08:18 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? [email protected] Excel Worksheet Functions 5 March 12th 07 10:38 PM
If then statement displaying 2 or 3 decimal places Miles Excel Worksheet Functions 2 February 27th 07 12:44 AM
How can I sort mostly 3 decimal with some 4 decimal numbers PeterM Excel Discussion (Misc queries) 4 August 16th 06 02:15 AM
If Statement - in time not decimal minutes Sue Excel Worksheet Functions 1 March 30th 05 04:35 PM


All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"