PDA

View Full Version : round function



lior03
09-13-2006, 11:43 PM
hello
how can i toggle the round function

Dim N As Integer
N = InputBox("Enter round required.")
selection = Application.Round(selection, N)

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

mdmackillop
09-14-2006, 12:42 AM
Hi Mosh,
A bit of WIP, but no more time

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

lior03
09-14-2006, 01:53 AM
hello
can i use the following

With ActiveWorkbook.Styles.add(name:="solver")
.numberformat = Application.WorksheetFunction.Round(ActiveCell, -2)
.Font.name = " arial"


thanks

mdmackillop
09-14-2006, 02:52 AM
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.

Cyberdude
09-15-2006, 10:58 AM
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?