Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default negative number

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


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default negative number

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.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default negative number

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I subtract a negative number from a positive number? csanta Excel Discussion (Misc queries) 5 April 4th 23 10:15 AM
Change positive number to negative number Angie M. Excel Worksheet Functions 1 January 25th 10 05:49 AM
Converting Negative Number to Postive number Tedd Excel Worksheet Functions 7 September 2nd 09 04:34 PM
Converting a negative number to a positive number Barb Excel Discussion (Misc queries) 3 November 1st 07 02:20 AM
2003= negative number&2004= negative number How Do I Calculate gro Jason Excel Worksheet Functions 1 January 14th 05 05:24 PM


All times are GMT +1. The time now is 08:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"