ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   RoundUp not working in VBA (https://www.excelbanter.com/excel-programming/418239-roundup-not-working-vba.html)

[email protected]

RoundUp not working in VBA
 
Can anyone provide insight into why the following is not working?

x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)

cost = 1
follow_up = 0.5

but x is coming out as 0 instead of 1

Thanks.

Don Guillett

RoundUp not working in VBA
 
I just did this and got 1

Sub rr()
cost = 1
follow_up = 0.5
x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)
MsgBox x
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Can anyone provide insight into why the following is not working?

x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)

cost = 1
follow_up = 0.5

but x is coming out as 0 instead of 1

Thanks.



Michael Hudston

RoundUp not working in VBA
 
It worked for me. However I did put some msgbox to check the values of cost
and follow_up before doing the calculation. I suggest the same, and double
checking the numbers you are feeding into the roundup

I did it like this

Private Sub Test_Click()

Dim Cost As Double
Dim Follow_up As Double
Dim x As Double

Cost = 1

MsgBox Cost

Follow_up = 0.5

MsgBox Follow_up

x = Application.WorksheetFunction.RoundUp((Cost * Follow_up), 0)

MsgBox x


End Sub


" wrote:

Can anyone provide insight into why the following is not working?

x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)

cost = 1
follow_up = 0.5

but x is coming out as 0 instead of 1

Thanks.


Barb Reinhardt

RoundUp not working in VBA
 
It's working here when cost and follow_up are defined before X.

You may want to add a debug.print

Debug.print Cost, Follow_UP

before the X =

to see what you really have.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



" wrote:

Can anyone provide insight into why the following is not working?

x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)

cost = 1
follow_up = 0.5

but x is coming out as 0 instead of 1

Thanks.


[email protected]

RoundUp not working in VBA
 
Figured out the problem -- follow_up was dimmed as an integer so it
was = 0 instead of 0.5

Thanks!

On Oct 8, 9:39*am, "Don Guillett" wrote:
I just did this and got 1

Sub rr()
cost = 1
follow_up = 0.5
x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)
MsgBox x
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
wrote in message

...

Can anyone provide insight into why the following is not working?


x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)


cost = 1
follow_up = 0.5


but x is coming out as 0 instead of 1


Thanks.



Rick Rothstein

RoundUp not working in VBA
 
I see you have resolved your problem, but I thought I might mention that
although VB does not have a ROUNDUP function equivalent without going to the
worksheet functions, there is a simple math procedure to do the same thing
you are looking for (round up to an integer)...

If Variable is always non-negative: x = -Int(-Variable)

If negative values are permitted: x = -Sgn(R) * Int(-Abs(R))

--
Rick (MVP - Excel)


wrote in message
...
Can anyone provide insight into why the following is not working?

x = Application.WorksheetFunction.RoundUp((cost * follow_up), 0)

cost = 1
follow_up = 0.5

but x is coming out as 0 instead of 1

Thanks.




All times are GMT +1. The time now is 12:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com