negative number

F

Frank Kabel

Hi
why use VBA?.
one way (without VBA) would be the following
- enter '-1' in a blank cell
- copy this cell (CTRL+C)
- select A1:A7
- goto 'Edit - Paste Special' and choose 'Multiply' as action

For a VBA solution you may try the following macro (makes all numbers
negative in the current selection - already negative numbers won't be
altered)
Public Sub make_negative()
Dim c As Range
For Each c In Selection
If c.Value > 0 Then
c.Value = -c.Value
End If
Next
End Sub

Note: no error checking included for strings, etc.
 
D

david fixemer

Sub macro1()
For Each c In Range("A1:A7").Cells
c.Value = 0 - c.Value
Next
End Sub

Note: I subtracted from zero, you could also multiply by -
1.
 
Y

Young-Hwan Choi

This will work whether the cells have a negative or positive value.

Sub neg_Value()
Dim aaa As Range
For Each aaa In Range("A1:A7")
aaa = -Abs(aaa) 'if you want them to be positive, remove "-"
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top