Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a number like 2.138 which I want to round to two decimal places. What is the command to do this? Within a spreadsheet it's round(2.138,2) but this does not seem to work in VBA. I had read somewhere that all excel spreadsheet commands work within VBA but this doesn't seem to be true. Can anyone elaborate? Thanks guys. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jamie
various options - in the Immediate Window: ?Application.WorksheetFunction.ROUND(2.138,2) 2.14 ?WorksheetFunction.ROUND(2.138,2) 2.14 ?Application.ROUND(2.138,2) 2.14 ?ROUND(2.138,2) 2.14 Regards Trevor wrote in message ... Hi, I have a number like 2.138 which I want to round to two decimal places. What is the command to do this? Within a spreadsheet it's round(2.138,2) but this does not seem to work in VBA. I had read somewhere that all excel spreadsheet commands work within VBA but this doesn't seem to be true. Can anyone elaborate? Thanks guys. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You need to qualify the worksheet function using either
the WorksheetFunction or Application properties: Sub XXX() Dim Num As Single Num = 2.1234 MsgBox WorksheetFunction.Round(Num, 2) MsgBox Application.Round(Num, 2) End Sub -----Original Message----- Hi, I have a number like 2.138 which I want to round to two decimal places. What is the command to do this? Within a spreadsheet it's round(2.138,2) but this does not seem to work in VBA. I had read somewhere that all excel spreadsheet commands work within VBA but this doesn't seem to be true. Can anyone elaborate? Thanks guys. . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try putting the formula into the relevant cell with this VBA code
Range("A1").FormulaR1C1 = "=ROUND(2.138,2)" If it is within the VBA code that you wish to convert the number by assignment to a variable use Dim myVar as Double myVar = 2.138 myVar = Round(myVar, 2) Cheers Nigel wrote in message ... Hi, I have a number like 2.138 which I want to round to two decimal places. What is the command to do this? Within a spreadsheet it's round(2.138,2) but this does not seem to work in VBA. I had read somewhere that all excel spreadsheet commands work within VBA but this doesn't seem to be true. Can anyone elaborate? Thanks guys. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You guys are the best. Thanks a heap for the solutions
On Fri, 21 May 2004 05:21:59 GMT, ) wrote: Hi, I have a number like 2.138 which I want to round to two decimal places. What is the command to do this? Within a spreadsheet it's round(2.138,2) but this does not seem to work in VBA. I had read somewhere that all excel spreadsheet commands work within VBA but this doesn't seem to be true. Can anyone elaborate? Thanks guys. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
Show a "$" at the beging of this result =ROUND(D99*0.75,4)&".00 Ro | Excel Discussion (Misc queries) | |||
Standard font in a "New Microsoft Excel Worksheet.xls" wont change | Excel Discussion (Misc queries) | |||
How do I use the "if" and "round" function in the same formula ? | Excel Worksheet Functions | |||
Error msg "Microsoft Excel is waiting for another application to complete an OLE action" | Excel Programming |