Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Cornelius
 
Posts: n/a
Default Change decimal format of cells depending on conditions?


Hi all. I'm looking to change the format of cells to two-decimals when they
represent price per pound, but switch to comma-format when otherwise. This
is because the sheet shows lbs, dollars or price depending on the switch
selected, or combinations of them in different areas, and the lbs and dollars
columes are in the millions (decimals are confusing to the audience in this
case).

Thanks
ccc
  #2   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default

On Thu, 24 Feb 2005 15:23:08 -0800, Cornelius
wrote:


Hi all. I'm looking to change the format of cells to two-decimals when they
represent price per pound, but switch to comma-format when otherwise. This
is because the sheet shows lbs, dollars or price depending on the switch
selected, or combinations of them in different areas, and the lbs and dollars
columes are in the millions (decimals are confusing to the audience in this
case).

Thanks
ccc


You can do that by using a VBA event triggered macro (Worksheet_Change, for
example).

Here is an example assuming that your values are in A1:A10 and your "switch" is
in the adjacent column B1:B10. You will obviously have to modify this to suit
your needs.

=========================
Private Sub Worksheet_Change(ByVal Target As Range)
Dim v As Range, switch As Range

Set v = Range("A1:A10")
Set switch = Range("B1:B10")

If Not Intersect(Target, v) Is Nothing Then
Select Case Target.Offset(0, 1).Value
Case Is = "$/lb"
Target.NumberFormat = "#.00"
Case Is = "$", "lb"
Target.NumberFormat = "#,#"
Case Else
Target.NumberFormat = "General"
End Select
End If

If Not Intersect(Target, switch) Is Nothing Then
Select Case Target.Value
Case Is = "$/lb"
Target.Offset(0, -1).NumberFormat = "#.00"
Case Is = "$", "lb"
Target.Offset(0, -1).NumberFormat = "#,#"
Case Else
Target.Offset(0, -1).NumberFormat = "General"
End Select
End If


End Sub
=====================


--ron
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
I Need to change reference sheet for all cells on a form Brent E Excel Discussion (Misc queries) 1 February 11th 05 01:36 AM
How to get excel cells to change colors depending on value KV Excel Worksheet Functions 2 November 25th 04 09:50 AM
When I select "format cells", the format dialog box does not disp. Andy S. Excel Worksheet Functions 2 November 23rd 04 03:49 AM
Change format of cells williamaleng@ti Excel Worksheet Functions 0 November 14th 04 02:28 PM
Change format of cells williamaleng@ti Excel Worksheet Functions 2 November 14th 04 09:14 AM


All times are GMT +1. The time now is 06:26 PM.

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

About Us

"It's about Microsoft Excel"