View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Format cell to show '-'

Try this code then...

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, Range("A4:A27,E2:E8,H3:H9")) Is Nothing Then
With Target
.Value = -Abs(.Value)
End With
Application.EnableEvents = True
End Sub

Note that in keeping with my response to Gary''s Student, I changed the
assignment line to make any entry, positive or negative, into a negative
number.

--
Rick (MVP - Excel)


"Gary" wrote in message
...
Need the following:
A4:A27
E2:E8
H3:H9

"Rick Rothstein" wrote:

So... tell us the range of cells you want it to apply to and we will
change
the code accordingly.

--
Rick (MVP - Excel)


"Gary" wrote in message
...
I am wanting this feature to apply to certain ranges of cells. I
believe
this will affect the entire worksheet?
Regards
Gary

"Gary''s Student" wrote:

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
With Target
.Value = -.Value
End With
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic
to
use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200852


"Gary" wrote:

they do not have to display as negative, but I want them to function
as
negative. If any number is entered, it will be seen as a negative
number by
formula referencing that cell.

Thanks,
Gary

"Rick Rothstein" wrote:

Can there be actual negative values in your cells and, if so, how
should
they display?

--
Rick (MVP - Excel)


"Gary" wrote in message
...
Looking for a way to make entries into cell show negative (-)
indicator by
default. For instance if '1' is entered, it will display '-1'.
Excel 2003