In Excel I'm trying to compute a value which depends on other range value. I have a very strange problem: the same formula with different value doesn't work for some case.
This formula works:
ROUNDUP(AVERAGE(IF(RangeName1=1;RangeName2));2)*100&" %."
This one doesn't:
ROUNDUP(AVERAGE(IF(RangeName1=2;RangeName2));2)*100&" %."
I check and my RangeName1 does contain these values: 1 and 2 (order like this).
Does anybody has an idea why the second formula doesn't work?
When I try your formula's both work fine.
Can you tell us what you are trying to achieve?
If you want to display percentage in a cell you could also use cell formatting, this way your cell will only contain the actual number displayed in a certain way instead. see http://www.excel-easy.com/basics/format-cells.html for reference.
Related
I am trying to use a variable range based on a pre-defined criteria. In my case I would like to find the range of the “AUD” cells in the table. I managed to get the beginning of the range thanks to:
=ADDRESS(1;MATCH("AUD";1:1;0))
And then I found the end of the range using a slightly modified above formula:
=ADDRESS(1;(MATCH("AUD";1:1;0)+(COUNTIF(1:1;"AUD"))-1))
Then I simply combined the results with the following formula:
=(B4&":"&C4)
And the achieved result was:
$B$1:$D$1
However, I am having difficulties implementing this result inside formulas in which range must be defined, which brings me to my following questions:
Is such kind of implementation possible in EXCEL, I suspect that the result is considered as a simple text and not actually a cell reference? Is there a way I can change that?
One step further, if we trim (for example from $B$1 to just $B) can we still make the formula working?
Due to the fact that to save space I will probably write all the above formulas inside one formula and I expect this formula to become huge, would it be possible to create a VBA public function which can store the range in a variable and then just refer this variable to the formula - for example, SUMIF("=audRefCell()";"AUD";2:2).
I would like to thank you in advance for the help!
I'm having a problem writing my formula that should count all selected cells that contain a number bigger than 0 and skip the cells that are completely empty, even when the cell is selected. Excel gives me an error that I selected cells that not contain a number. How can I skip them?
This is my formula:
=COUNTIFS(C8:C12;E8:E12;G8:G12;I8:I12;K8:K12;">0")
I'm thinking you using the COUNTIFS() formula wrong, after each range, there is a criteria. You can't have multiple ranges like that to look through. For more information look here or here.
In your case you are dealing with a non continues range, and one way to deal with that would be this
So the formula would translate to:
=SUM(COUNTIF(INDIRECT({"C8:C12","E8:E12","G8:G12","I8:I12","K8:K12"}),">0"))
Another formula you could try is:
=INDEX(FREQUENCY((C8:C12,E8:E12,G8:G12,I8:I12,K8:K12),0),2)
And looking at your data, it seems as though the rest of the columns contain text (not sure, they may be dates). In case they are text values:
=SUMPRODUCT((ISNUMBER(C8:K12))*(C8:K12>0))
If they are actually dates (assuming from 2018), then you could try:
=SUMPRODUCT((YEAR(C8:K12)<2018)*(C8:K12>0))
I'm assuming this is what you looking for, instead of a VBA based solution due to the tags provided and your formula.
You could also do it in this particular case by skipping the columns that you don't want:
=SUMPRODUCT((C8:I12>0)*ISEVEN(COLUMN(C8:I12)-COLUMN(C8)))
what will be happen if you use the below formula? to you receive an error?
=COUNTIF(C8:C12,">0")+COUNTIF(E8:E12,">0")+COUNTIF(G8:G12,">0")+COUNTIF(I8:I12,">0")+COUNTIF(K8:K12,">0")
Try this
Requirement cannot be done in single formula,
combining 2 or more formula will help fixing the formula.
formula
=COUNTA(B2:B9,D2:D9) -- Count all the non blank cell's
=COUNTIF(B2:B9,"=0")+COUNTIF(D2:D9,"=0") -- Count all the cells will value as 0
Subtract both which will give the output you are looking for
Combined formula
=COUNTA(B2:B9,D2:D9)-(COUNTIF(B2:B9,"=0")+COUNTIF(D2:D9,"=0"))
Can't believe I don't know this, but is there a way to avoid repeating a formula in an if statement if the logical test is dependent on it?
i.e.
=IF((SUMIFS formula)=0,"",SUMIFs formula)
I want to replace that SUMIFS function in the false scenario with something short that will tell it to just programmatically repeat the formula it originally tested for. Repeating the formula twice has to have detrimental effects on processing speed. Negligible, maybe, but want to go for best-practices here. Thanks.
You can force an error like #DIV/0! and then use IFERROR, e.g.
=IFERROR(1/(1/SUMIFS_formula),"")
You can assign a Name to a formula and use the Name..............See:
Assigning a name to a formula
Relevant excerpt -
For example, let's suppose we frequently use a formula like:
=SUM(A1:A100)-SUM(B1:B100) and this resides in A101 and is copied across many columns on row 101. It would be better in this case to
create a custom formula that does this in each cell on row 101. Here
is how;
1) Select cell A101 (this is vital).
2) Go to Insert>Name>Define and
in the "Names in workbook" box type: SalesLessCosts
3) Now click in
the "Refers to" box and type: =SUM(A1:A100)-SUM(B1:B100) then click
Add.
Now you can replace the formula in cell A101 with: =SalesLessCosts.
You can also copy this across row 101 and it will change its relative
references just as the formula =SUM(A1:A100)-SUM(B1:B100) would. The
reason it does this is all down to the fact we selected A101 before
going to Insert>Name>Define and used relative references in
=SUM(A1:A100)-SUM(B1:B100) when we added it to the "Refers to" box.
If all you need to do is hide zeroes, there is an easy way:
Select all cells where you wish to hide zeroes
Go into Custom Number Formatting
Set format to "General;General;"
The custom formatting has a structure of [positive numbers];[negative numbers];[zeroes]
By making the last part blank you are effectively hiding zeroes, but showing everything else.
The advantage over conditional formatting is that you can use this on any background.
A neat trick which I sometimes use is to hide the cell value completely by using a custom format of ";;;". This way you can put images inside the cells, like the conditional formatting ones, and not see the value at all.
Try using the SUBSTITUTE function like this :
=SUBSTITUTE( VLOOKUP( H4; $D$5:$E$8; 2; 0 ); $H$1; $I$1 )
Here is an example:
Here the formula I don't want to repeat twice is the VLOOKUP function.
The result of VLOOKUP is a string found in another table (ex : "Green").
I want to check if that string matches a specific string value in $H$1 (here, "Yellow").
If it does, SUBSTITUTE replaces it with$I$1 (the error string you want. Here, "FORBIDDEN").
If it doesn't, it displays the VLOOKUP result string (the normal authorized output, like "Green").
This is useful for me because my actual formula is quite long, so I don't want to write it twice.
I also dont want to use two different cells, because I'm already applying this formula on 10 columns, meaning I should add an extra 10 columns to make it work.
In some scenarios, MAX() or MIN() can do a wonderful job.
E.g., something like this:
=IF(SUMIFSformula>0,SUMIFSformula, 0)
Can be shortened to this:
=MAX(0,SUMIFSformula)
The LET formula can be used for this exact scenario. You can define the formula as a variable and then within that same cell you can reference the variable in your formula.
The LET formula format looks like this:
=LET(name,name_value,calculation)
SUMIFS Example
Here's how it would work with your SUMIF example so that you don't have to repeat the formula:
In this screenshot we have an array A1:B7. We want to sum the values (Col B) if the name in ColA is "apple".
For this we have a standard SUMIFS formula of
=SUMIFS(B1:B7,A1:A7,"apple")
The formula is showing in E2. The result is shown in E3.
To put this into the IF statement without having to repeat the formula we can use LET as shown in the screenshot.
We create a variable with the SUMIFS formula as the value of that variable. We then write our IF statement using the variable name instead of rewriting the formula multiple times.
=LET(name,name_value,calculation)
Variable name: sumapples
Variable value: SUMIFS(B1:B7,A1:A7,"apple")
Calculation: IF(sumapples=0,"",sumapples)
Put together in the LET function it looks like this:
=LET(sumapples,SUMIFS(B1:B7,A1:B7,"apple"),IF(sumapples=0,"",sumapples))
This LET function can be used in any Excel formula, and is very useful for shortening long formulas that have repetition.
Optional: Extra complexity
If you want to you can get extra complicated by naming multiple variables.
=LET(name,name_value,name2,name_value2,calculation)
Since Excel 2007, the IFERROR statement does what the OP asked. From the help file:
Description:
Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. [italics mine]
Syntax:
IFERROR(value, value_if_error)
I've since realised that this was already answered by #barry houdini above.
Here is a hack - depending on whether you are just interested in the displayed value, or whether you need to use the value in another formula:
Put your SUMIF formula in the cell (without the IF part)
Create a conditional formatting rule which sets the font color to the background color when the cell value is 0
And hey presto, you get the desired result.
As I said - it's a hack, but it does prevent the double evaluation.
There is no "clean" solution that I am aware of.
Here is my problem:
I have a cell (V4) containing the value 444. I want to use this value in the formula of another cell (M12) in the following way. I want the formula to be equivalent to =MIN(L12:L444) but instead of 444 I want to refer to cell V4 which contains the value 444. But when I type in =MIN(L12:L(V4)) it obviously doesnt work so how do I do it? Sorry if I didn't explain it very well. :S
Would this work for you:
=MIN(L12:INDIRECT("L"&$V$4))
From: Excel - INDIRECT and Using the value in a cell as a cell reference in a formula?
INDIRECT will work and is closest to the solution you described, but I prefer OFFSET, which uses proper references. (For example, if you insert a column in the sheet before L, INDIRECT will break while OFFSET will just update its reference as expected.
Two ways to go with OFFSET:
1 - Start at L$1 and go down $V$4-1 rows. (This will work with $V$4 as you've defined it now.)
=MIN(L12:OFFSET(L$1,$V$4-1,0))
2 - In $V$4, provide the height of the range you want.
=MIN(OFFSET(L12,0,0,$V$4,0))
It's hard to make suggestions without more context, but I'm sure you can tweak one of these patterns to meet your needs.
I am not sure if you are trying to include all of the values in 1 column and then on non-contiguous cell. If so, it should look like = Min(L12:L444,V4) . The L12:L444 looks at the value in every cell in the L column from 12 - 444.
So you can check individual cell (A3, D15, Q54) with commas, or a range of cells (A3:Z54) with a colon. Or a range and a specific cell like above =Min(L12:L444, V4).
I have to restrict some invalid data in a Excel Column.
Below is Validation Criteria:
Should be a numeric Number
Size/Length should be equals to 9
Ex : valid:602005514, invalid:were,43456 etc.
I have created a Custom Data Validation using below function.
=AND(LEN(INDIRECT(SUBSTITUTE(ADDRESS(ROW(),COLUMN()),"$","")))=9,
ISNUMBER(INDIRECT(SUBSTITUTE(ADDRESS(ROW(),COLUMN()),"$",""))))
//here i have to get cell name dynamically. so, i have used ADDRESS function
But its not working as expected. It is not allowing any value in cell.
I guess it might be because of LEN function circular reference.
I have tried many ways, but not able to solve it. Please help me to solve this.
You don't need to resort to INDIRECT etc, in you formula just refer to top left cell in the range you are applying the validation.to. Excel will adjust for the othger cells in the range. When entering cell references don't use absolute references, ie no $'s
Eg select a range starting at cell A1, and set data validation formula to
=AND(ISNUMBER(A1),LEN(A1)=9)
Check this simple validation .. checking Cell D13 ..
=IF(LEN(D13)=9,IF(ISNUMBER(D13),"yes","no"),"no")
Another way:
=AND(ISNUMBER(A1),A1>99999999)
Make sure there are no leading or trailing spaces in the cell:
=IF(TRIM(A3)=A3,TRUE,FALSE)