Home |
Search |
Today's Posts |
#12
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
orangie
Try this version which preserves the formula in the cell. Sub RoundAdd() Dim myStr As String Dim cel As Range For Each cel In Selection If cel.HasFormula = True Then If Not cel.Formula Like "=ROUND(*" Then myStr = Right(cel.Formula, Len(cel.Formula) - 1) cel.Value = "=ROUND(" & myStr & "," & "2" & ")" End If End If Next End Sub Gord Dibben MS Excel MVP On Wed, 21 Mar 2007 12:45:26 -0700, orangie wrote: I'm trying to use this macro but am having an application, unknown object error: Option Explicit Sub round_made_easy() Dim myCell As Range For Each myCell In Selection.Cells myCell.Formula = "=Round(" & myCell.Formula & ",2)" Next myCell End Sub Now when I try the above it gives me an application error. But with the following code that you gave me it works great. Option Explicit Sub round_made_easy() Dim myCell As Range For Each myCell In Selection.Cells myCell.Formula = "=Round(" & myCell.Value & ",2)" Next myCell End Sub why won't it work for a cell that is =1258/4569871 and keep the 1258/4569871 in the cell's formula of =Round(1258/4569871, 2) ??? Thanks! "orangie" wrote: Thanks! "Dave Peterson" wrote: You could use a macro. Select the cells to fix and run this: Option Explicit Sub testme() Dim myCell As Range For Each myCell In Selection.Cells myCell.Formula = "=Round(" & myCell.Value & ",2)" Next myCell End Sub If you're new to macros, you may want to read David McRitchie's intro at: http://www.mvps.org/dmcritchie/excel/getstarted.htm orangie wrote: I have a value in a cell, say A2 =5.62345. And I want to add a formula to this value in this cell, basically =round(5.62345, 2), but i have 30+ cells with values and I don't want to go into each cell individually. is there anyway to avoid this? Thanks! -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
adding a formula in a cell but when cell = 0 cell is blank | Excel Worksheet Functions | |||
Cannot enter formula in a cell after removing a circular formula | Excel Worksheet Functions | |||
Cell Formula reference to cell Based On third Cell Content | Excel Discussion (Misc queries) | |||
Cell Formula reference to cell Based On third Cell Content | Excel Discussion (Misc queries) | |||
Cell doesn't show formula result - it shows formula (CTRL + ' doe. | Excel Worksheet Functions |