Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Need help with rounding in VBA code

When I try to break a value into 3 equal parts

ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[1]C/3"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=(R[2]C-R[1]C)/2"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[3]C-(R[2]C+R[1]C)"

it works fine, but how can I Round each new amount to 2 decimals for
currency?
I have some with 8 or 10 #'s after the decimal, not what I want.
kind of like
ActiveCell.FormulaR1C1 = Round("=R[1]C/3",2)
but I know that won't work.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Need help with rounding in VBA code

With ActiveCell
.Offset(-1, 0).Range("A1").FormulaR1C1 = "=ROUND(R[1]C/3,2)"
.Offset(-1, 0).Range("A1").FormulaR1C1 = "=ROUND((R[2]C-R[1]C)/2,2)"
.Offset(-1, 0).Range("A1").FormulaR1C1 =
"=ROUND(R[3]C-(R[2]C+R[1]C),2)"
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"OzonedMan" wrote in message
...
When I try to break a value into 3 equal parts

ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[1]C/3"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=(R[2]C-R[1]C)/2"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[3]C-(R[2]C+R[1]C)"

it works fine, but how can I Round each new amount to 2 decimals for
currency?
I have some with 8 or 10 #'s after the decimal, not what I want.
kind of like
ActiveCell.FormulaR1C1 = Round("=R[1]C/3",2)
but I know that won't work.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Need help with rounding in VBA code

Does this help

Sub doformulas()
With ActiveCell
.Offset(-1).FormulaR1C1 = "=round(R[1]C/3,2)"
.Offset(-2).FormulaR1C1 = "=round((R[2]C-R[1]C)/2,2)"
.Offset(-3).FormulaR1C1 = "=round(R[3]C-(R[2]C+R[1]C),2)"
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"OzonedMan" wrote in message
...
When I try to break a value into 3 equal parts

ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[1]C/3"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=(R[2]C-R[1]C)/2"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[3]C-(R[2]C+R[1]C)"

it works fine, but how can I Round each new amount to 2 decimals for
currency?
I have some with 8 or 10 #'s after the decimal, not what I want.
kind of like
ActiveCell.FormulaR1C1 = Round("=R[1]C/3",2)
but I know that won't work.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Need help with rounding in VBA code

Try something like this

activecell.formulaR1C1="=ROUND(R[1]C/3,2)"

HTH,
Barb Reinhardt

"OzonedMan" wrote:

When I try to break a value into 3 equal parts

ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[1]C/3"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=(R[2]C-R[1]C)/2"
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=R[3]C-(R[2]C+R[1]C)"

it works fine, but how can I Round each new amount to 2 decimals for
currency?
I have some with 8 or 10 #'s after the decimal, not what I want.
kind of like
ActiveCell.FormulaR1C1 = Round("=R[1]C/3",2)
but I know that won't work.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Need help with rounding in VBA code

If you need a VBA solution google VBRound on this newsgroup. You'll
need to do that thing where you multiply by one hundred on the VBRound
argument and divide by one hundred on the VBRound result.



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
ROUNDING FORMULA =ROUND(B12/$B$10,1) ROUNDING TO HIGH SunshineinFt.Myers[_2_] Excel Worksheet Functions 7 March 5th 09 06:41 PM
I need a formula with rounding up & rounding down to the nearest . Tony Kay Excel Worksheet Functions 3 May 29th 07 11:13 PM
Worksheet rounding vs VBA rounding Simon Cleal Excel Programming 4 September 2nd 05 01:50 AM
Code not rounding Otto Moehrbach[_6_] Excel Programming 3 July 25th 04 01:47 AM
Rounding questions: (Formula and Code) ? Stuart[_5_] Excel Programming 2 April 8th 04 07:05 PM


All times are GMT +1. The time now is 08:50 AM.

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"