Share via

Macro for Increasing/Decreasing Decimal

Anonymous
2017-02-10T10:59:21+00:00

Very often I need to increase/decrease decimal in large tables which have percentages and absolute numbers.

If I select all and make the change, percentage get converted in number format. Selecting numbers one by one to increase/decrease decimal is inefficient as I need to do this in various such tables.  Is there a way to inc/dec decimals without screwing the number formats in the cells selected?

***Post moved by the moderator to the appropriate forum category.***

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2017-02-10T16:12:01+00:00

    Select your cells and run one of these

    Sub IncreaseDecimal()

        Dim rngc As Range

        For Each rngc In Selection

            If rngc.NumberFormat = "0" Or rngc.NumberFormat = "0%" Then

                rngc.NumberFormat = Replace(rngc.NumberFormat, "0", "0.0")

            Else

                rngc.NumberFormat = Replace(rngc.NumberFormat, "0.0", "0.00")

            End If

        Next rngc

    End Sub

    Sub DecreaseDecimal()

        Dim rngc As Range

        For Each rngc In Selection

            If InStr(1, rngc.NumberFormat, "0.00") > 0 Then

                rngc.NumberFormat = Replace(rngc.NumberFormat, "0.00", "0.0")

            Else

                rngc.NumberFormat = Replace(rngc.NumberFormat, "0.0", "0")

            End If

        Next rngc

    End Sub

    Was this answer helpful?

    0 comments No comments