Consulting

Results 1 to 5 of 5

Thread: round function

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    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

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  3. #3
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    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

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  5. #5
    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
  •