1. Registered User
Join Date
Mar 2006
Posts
5

I will make this short (beginner here). I am working with numbers that I would like to round up to the nearest thousands or so. Like 28,230 to 28,000 or 134,634 to 135,000, I have seen the round function but it is not working for me. Any help would be great.

2. Grand Poobah
Join Date
Sep 2003
Location
MI
Posts
3,713
dim MyLong As Long, Remainder As Integer

MyLong=123,456
Remainder=MyLong MOD 1000
MyLong=MyLong+IIf(Remainder>500,1000,0)
MyLong=CLng(MyLong/1000)*1000

Next question ...

3. Registered User
Join Date
Mar 2006
Posts
5
Thank you very much, that was fast.... I will get it a try.

4. Grand Poobah
Join Date
Sep 2003
Location
MI
Posts
3,713
Oops! Check the last line:

MyLong=CLng(MyLong/1000)*1000

Should be:

MyLong=CLng(MyLong \ 1000)*1000

The 1st will promote the rounding up ... Real Division
The latter will truncate the remainder ... Integer Division

Whew!

5. Registered User
Join Date
Mar 2006
Posts
5
Ok, great...

6. Registered User
Join Date
Mar 2006
Posts
5
I must be doing something wrong I keep getting Expected: End of Statement error. ???? The first part MyLong=123,456 is highlited in red. ? Sorry I'm not to good at this.

7. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
I've just been playing with Mike's function too He just Inspired a little vbRound function that allows rounding either side of the decimal place. Thanks for the idea Mike!

Anyhoo - remove the comma.

8. Grand Poobah
Join Date
Sep 2003
Location
MI
Posts
3,713
Originally Posted by mustgo35
I must be doing something wrong I keep getting Expected: End of Statement error. ???? The first part MyLong=123,456 is highlited in red. ? Sorry I'm not to good at this.
My bad. Difference between what you display (to read) and what you type to work (program) ...

Pootle hit it right on the head (was that 1 lump or 2?)... Remove that comma.

Should be: 123456

9. Registered User
Join Date
Mar 2006
Posts
5
Thanks guys!!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•