How to pass a value to woksheet function with macro

Jean-Pierre

New Member
Joined
Sep 15, 2009
Messages
3
I need to round the result of a ( or several ) selected cell(s) wich already contains several figures wich I must keep. Exemple: 500+200+109 The cell display the value of 809. If I apply a round formula I will loose the info of what amounts where added. So I wrote the following code as a starting point but it is not working:

Sub arrondir()
Dim cell As Range
Dim myValue As Single
For Each cell In Selection
myValue = cell.Value
cell.Formula = "=MROUND(("myValue"),100)":crash:
Next cell
End Sub


If i were to use the vba function, the answer would replace the amounts that were added and I dont want that.

Thank you for any suggestion.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Use a worksheet function.

Code:
Sub arrondir()
Dim cell As Range
Dim myValue As Single
For Each cell In Selection
myValue = cell.Value
myValue = application.worksheetfunction.mround(myValue,100)
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top