A different formula similar to an If statement

FedElecQaEng

New Member
Joined
Sep 25, 2023
Messages
12
Office Version
  1. 2010
Platform
  1. Windows
I make use of the If statement a lot and sometimes the formula returns a 0. When the main formula returns a zero I want it to show the dash character so I usually make a formula like this:

=If(*Formula* = 0,"-",*Formula*)

My main question is if there is a way to not have to repeat the formula twice especially since sometimes the main formula can fill up more than half the formula bar, and sometimes I make changes to the main formula (making the same change twice multiple times can get annoying and time-consuming).


Something I would like is similar to the IFERROR function where, if the formula returns an error then return a different value, else return the formula value (In these cases I also make use of the "-" character)
Following the IFERROR format, a made-up formula that I can imagine as an example would be like =IFVAL([logical formula],[value],[value_if_same]). So if [logical formula] returns the value in [value] then IFVAL returns the [value_if_same] else IFVAL returns the value from [logical formula]
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Excel Formula:
=IFERROR(1/(1/(your formula)),"-")
 
Upvote 0
You might use custom formatting instead:

MrExcelPlayground20.xlsx
IJ
1014
1123
1232
1341
145-
156-1
167-2
Sheet16
Cell Formulas
RangeFormula
J10:J16J10=5-I10


If you are looking to change 0 specifically, then

MrExcelPlayground20.xlsx
IJK
10144
11233
12322
13411
145--
156-1-1
167-2-2
Sheet16
Cell Formulas
RangeFormula
J10:J16J10=5-I10
K10:K16K10=IFERROR(1/(1/(5-I10)),"-")
 
Upvote 0
That IFERROR formula is good when I am using just numerical values (and I thank you for that and will try to remember it when I come across it) but mostly I make use of strings and characters.

My formula use INDEX-MATCH alot for searching tables of data and some of the cells in the data tables are blank which in turn returns a 0. It is these instances that i want a "-" character.

The main sheet has the following formula used

Excel Formula:
=IFERROR(IF(INDEX('SHEET REFS'!$A:$Z,INDEX(GLOBAL!$AB:$AC,MATCH($H7,GLOBAL!$AB:$AB,0),2),MATCH(Q$3,'SHEET REFS'!$1:$1,0)) = 0,"-",INDEX('SHEET REFS'!$A:$Z,INDEX(GLOBAL!$AB:$AC,MATCH($H7,GLOBAL!$AB:$AB,0),2),MATCH(Q$3,'SHEET REFS'!$1:$1,0))),"-")

And would return the following as examples (I have conditional formatting to fills cells with "-" to gray)

1695648912902.png



'SHEET REF' contains the following formulas:

Excel Formula:
=INDIRECT("'" & GLOBAL!$I$3 & "'!" & CHAR(64 + COLUMN(P6)) & ROW(P6))

And has the following values:

1695648976045.png


(the GLOBAL sheet mainly contains names of other different sheets of data tables that i use SHEET REF to switch between when selections on the main sheet are made)

To finalize, sometimes cells in the comment column on SHEET REF contains a string so i want it to have that string on the main sheet, but when a cell on SHEET REF contains a 0 because of where it pulled the data from then on the main sheet i want to display a "-"

My question is if there is a way to perform the same function as the first formula on the main sheet without having to repeat the formula twice.
 
Upvote 0
You could use
Excel Formula:
=T(INDEX('SHEET REFS'!$A:$Z,INDEX(GLOBAL!$AB:$AC,MATCH($H7,GLOBAL!$AB:$AB,0),2),MATCH(Q$3,'SHEET REFS'!$1:$1,0)))
but this will return "" rather than "-"
 
Upvote 0
And would return the following as examples (I have conditional formatting to fills cells with "-" to gray)
Another option is to just change the CF from cells with "-" to cells with 0
 
Upvote 0
Thank you for the advice.
The T Function worked for the cells with text however some of the cells have dates and since it is a number excel was clearing out the value. The column with the date might change (based on the data table it is pulled from) so I cannot make a column specific to dates. For this specific instance, changing CF to cells with 0 worked, thank you.

The T function is useful though and I will make sure to remember that formula as it might be useful in other situations (on a side note is there a similar formula but for numeric instead)

What I will assume though is my main question of simplifying the IF function might not be possible. Sometimes the comparison value is not a 0 but rather a specific word.
An example formula I can think of that I would like to simplify would be =IF([Logical #1] = "CLOSED",[Logical #2],[Logical #1]). So if [Logical #1] is equal to "CLOSED" then perform [Logical #2] but if not then return the value from [Logical #1].
A simplified version that I am looking for would only need to have [Logical #1] appear once in the entire formula instead of twice.
 
Upvote 0
With xl2010 I don't think you have much option other than to use what you have already got.
 
Upvote 0
2010 is what I was provided with by my company, but I might be able to request a later version.

Any version that you can recommend and what i can use in that version?

Secondary question to a newer version, if someone else has Excel 2010 can they open/use a file that I create in the newer version?
 
Upvote 0
With either 2021 or 365 you have the LET function which would do what you want, but it will not work for anyone on an older version.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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