Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How do you "Round" a value in Microsoft Excel VB?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default How do you "Round" a value in Microsoft Excel VB?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default How do you "Round" a value in Microsoft Excel VB?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do you "Round" a value in Microsoft Excel VB?

Try

v = Application.Round(2.138, 2

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default How do you "Round" a value in Microsoft Excel VB?

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.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Show a "$" at the beging of this result =ROUND(D99*0.75,4)&".00 Ro bjminer Excel Discussion (Misc queries) 3 July 4th 07 08:56 PM
Standard font in a "New Microsoft Excel Worksheet.xls" wont change Prunetart Excel Discussion (Misc queries) 0 September 15th 06 10:36 AM
How do I use the "if" and "round" function in the same formula ? carl Excel Worksheet Functions 2 April 27th 06 04:37 PM
Error msg "Microsoft Excel is waiting for another application to complete an OLE action" JimPNicholls Excel Programming 0 January 16th 04 12:41 PM


All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"