Thread: negative number
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default negative number

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.



--
Regards
Frank Kabel
Frankfurt, Germany

How do i make all the numbers in Column A1 to A7 Negative using VB
Script?


---
Message posted from http://www.ExcelForum.com/