Hi,
I need to round up a number in VBA (Word 2000).
A number from a text box (X) is being will be used in a formula.
(X-100)/50
If the result has any decimal place, the answer needs to be rounded to the
next whole number.
For instance
(312-100)/50 = 4.24
4.24 needs to round up to 5
I know there is a roundup function in Excel, Is there an equivalent in VBA?
Any ideas on how to accomplish what I need?
Thanks.
jbc
Word Heretic - 16 Dec 2004 04:20 GMT
G'day jbc <jbc@discussions.microsoft.com>,
X=Int(X+0.99)
Steve Hudson - Word Heretic
steve from wordheretic.com (Email replies require payment)
Without prejudice
jbc reckoned:
>Hi,
>
[quoted text clipped - 18 lines]
>
>jbc
Greg Maxey - 16 Dec 2004 04:39 GMT
This is only tested to your example. You may need to proof it:
Sub Test()
Dim X As String
Dim Z As Long
X = (312 - 100) / 50
If X > Int(X) Then
Z = 1
Else: Z = 0
End If
MsgBox Round((X + Z), 0)
End Sub

Signature
Greg Maxey/Word MVP
A Peer in Peer to Peer Support
> G'day jbc <jbc@discussions.microsoft.com>,
>
[quoted text clipped - 29 lines]
>>
>> jbc
Andi Mayer - 16 Dec 2004 09:15 GMT
>Hi,
>
[quoted text clipped - 6 lines]
>If the result has any decimal place, the answer needs to be rounded to the
>next whole number.
result= -Int(-expresion)
the integer of an negativ number is everytime the higher number,
regardless the amount behind the comma
rounding down is the same without the both minus
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
Greg - 16 Dec 2004 12:47 GMT
JBC,
There was an error in my previous post. Rather than fix it, I concede
that the solution Andi Mayer posted is far superior.
You know your formula looks similar to a formula that an OP last week
was using to determine a processing fee based on the number of pages
processed. Using VBA rather than field codes it could look something
like this:
Sub ScratchMacro()
Dim X As Double
X = (InputBox("Enter pages to process", "Input") - 100) / 50
If X <= 0 Then
MsgBox "The preparation fee is $150.00"
Exit Sub
End If
MsgBox "The preparation fee is $" & (-Int(-X) * 200) & ""
End Sub
jbc - 16 Dec 2004 14:41 GMT
Greg,
That's exactly what I'm doing. It's a processing fee for the US patent
office. I didn't want to bore you guys with too much "extra" information.
Was the other post last week? I'll have to search for it.
Thanks for your help...I'll be working on the form today.
jbc
> JBC,
>
[quoted text clipped - 15 lines]
> MsgBox "The preparation fee is $" & (-Int(-X) * 200) & ""
> End Sub