I improved the answer provided by Sumit Saha to provide the following features:
- Select a range or different ranges with the mouse
- Enter the number of digits required instead of editing the code
- Enter the number of digits for the different regions selected by changing the order of the iNum strings as described.
Hello,
Sub Round_Formula_EREX() Dim c As Range Dim LResult As Integer Dim leftstr As String Dim strtemp As String Set wSht1 = ActiveSheet Dim straddress As Range Dim iNum As Integer Set straddress = Application.Selection Set straddress = Application.InputBox("Range", xTitleId, straddress.Address, Type:=8) iNum = Application.InputBox("Decimal", xTitleId, Type:=1) For Each c In straddress If c.Value <> 0 Then strtemp = c.Formula LResult = StrComp(Left(strtemp, 7), "=ROUND(", vbTextCompare) If LResult <> 0 Then 'If you want to enter different digits for different regions you have selected, 'activate next line and deactivate previous iNum line. 'iNum = Application.InputBox("Decimal", xTitleId, Type:=1) c.Formula = "=ROUND(" & Right(c.Formula, Len(c.Formula) - 1) & "," & iNum & ")" End If End If Next c End Sub
source share