Rounding with VBA

Cricketer

Board Regular
Joined
Oct 14, 2002
Messages
217
Hello

I’m updating various cell values using Special Paste and this works fine but I need to Round the result to whole numbers. Can anyone please advise how to modify the macro below which fails at Cell contents line?

Range("W6").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "M"
Range("AH2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Range("K8:K15").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
CellContents = cell.FormulaR1C1 = "= Round(" & CellContents & ", " & RoundUp & ")"
End Sub

Cricketer
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
From what your code suggests - You want to a formula to roundup each cell value you have just pasted.

However if you use a formula in the cell you want to round up you will create several circular references

How about a loop through the cells you specified:

Code:
Dim c As Range
For Each c In Range("K8:K15")
    c.Value = Application.WorksheetFunction.RoundUp(c, 0)
Next
 
Upvote 0

Forum statistics

Threads
1,212,129
Messages
6,106,117
Members
447,996
Latest member
ANDYADAM

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