Can you do a conditional number format?

jasonconlon

Board Regular
Joined
Mar 14, 2002
Messages
80
Is it possible to set variable number formats via a function or conditional formatting in some way?


Here's the setup, with no formats set (i.e. all of a General number format) --
~ Cell A1 contains the value 1.
~ Cell A2 contains the value 0.
~ Cell A3 contains the value 1.
~ Cell B1 is list validated (no blanks allowed) to offer either "Count" or "Percent" only, and currently contains the value "Count".
~ Cell B2 contains the formula =IF($B$1="Count",COUNT($A$1:$A$100),SUM($A$1:$A$100)/COUNT($A$1:$A$100))

How can I set it so that B2 changes from a General format (which is fine for showing a 'Count' integer) to a percentage format when B1 is changed to "Percent"?


I can't see a Conditional Formatting option to do this.

I can't find a function that changes number formats.

Theoretically I could use a custom number format with condition operators (although I couldn't get this to work properly anyway) as:
[<1]0%;General
...but while this would change the number format for values between 0 and 1 to show as percentages, with other numbers in General format, there's still an issue for 0%-vs-0 and 100%-vs-1.

Any other ideas? (I imagine that B1 could be set to some sort of drop-down field with an associated macro, but I'd like to avoid macros if at all possible so that people don't have to deal with the macro warning; and also 'coz I'm not very familiar with programming them.)
 
The code will work using 97 if the values (there are only two of them) are manually entered. You can still keep the data validation for B1, deselect the option for a drop-down arrow, and insert text in the Input Message tab for the user to enter either "Count" or "Percent" so that message pops up when B1 is selected. The code is not triggered in 97 for drop-down entry, but it is triggered by manual entry.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top