Search code examples
excelrangenegative-numbervba

Change Range of Numbers to be Negative in VBA


I am trying to program a macro in excel. Ideally, I would select a group of cells with numbers and press a key and these numbers would all become negative. This would save me a great deal of time and I would appreciate a solution.


Solution

  • Consider:

    Sub Negativize()
        Dim cel As Range
        For Each cel In Selection
            cel.Value = -Abs(cel.Value)
        Next cel
    End Sub