-
round function
hello
how can i toggle the round function
[VBA]
Dim N As Integer
N = InputBox("Enter round required.")
selection = Application.Round(selection, N)
[/VBA]
i want to enable the user select the round level (N) he wants.
present the infornation and then return to the original figures.
please help
thanks
moshe
-
Hi Mosh,
A bit of WIP, but no more time
[VBA]
Option Compare Text
Sub Rounding()
Dim N As Integer, tmp As String
N = InputBox("Enter round required.", , 2)
For Each cel In Selection
If InStr(cel.Formula, "Round") Then
tmp = Replace(cel.Formula, "=Round(", "=", 1)
Ln = Len(Split(tmp, ",")(UBound(Split(tmp, ","))))
cel.Formula = Left(tmp, Len(tmp) - (Ln + 1))
Else
If Left(cel, 1) = "=" Then
cel.Formula = "=Round(" & Right(cel, Len(cel) - 1) & "," & N & ")"
Else
cel.Formula = "=Round(" & cel & "," & N & ")"
End If
End If
Next
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
hello
can i use the following
[VBA]
With ActiveWorkbook.Styles.add(name:="solver")
.numberformat = Application.WorksheetFunction.Round(ActiveCell, -2)
.Font.name = " arial"
[/VBA]
thanks
moshe
-
If you change the cell value, or modify it from a formula to a value, how do you restore (toggle) it?
Another approach would be to copy the worksheet and modify the required cells.
Not sure about styles, never use them, but I can look at them later.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Do you want to set the same rounding factor to ALL numbers on the sheet, -OR-
do you want to apply the user's factor to just specific numbers and leave the rest of them as they are?
When do you prompt the user for the rounding factor? Does the user start a macro?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules