Rounding number UP

J

jbc

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
 
G

Greg Maxey

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
 
A

Andi Mayer

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.

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
 
G

Greg

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
 
J

jbc

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top