How to switch zeros for blanks in a range in excel? - excel

I need to select a column from sheet1 and the selected column matches destination cell's row. I've got this code
INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1")))
but it selects blank values (empty cells) as zeros insted of empty cells!
I tried to fix it with something like
IF(
(
INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1"))
)=0;
"";
(INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1"))))
which of course doesn't work because I'm trying to apply the condition to a range instead of a value.
Is there any way to select the range
INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1")) picking
the blanks as blanks instead of zeros?

Is this what you are trying? I have put your formula inside the TRIM() formula.
=TRIM(INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1"))))
Note: Trim() will return a string. So if the cell is blank then you will get a blank but if the cell has a number then you will get the number as string
See this Example

I see you may not need an answer any more but I note that your original attempt will work - you can apply an IF to a range, i.e.
=IF(INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1"))="";"";INDIRECT(ADDRESS(2;ROW();;;"Sheet1")):INDIRECT(ADDRESS(101;ROW();;;"Sheet1")))
....but the INDIRECT/ADDRESS combination may not be required, you could return your original array with this formula
=INDEX(Sheet1!$2:$101;0;ROW())
and then just apply a simple IF function to that, i.e.
=IF(INDEX(Sheet1!$2:$101;0;ROW())="";"",INDEX(Sheet1!$2:$101;0;ROW()))
both of those will keep the numeric values numeric

Related

Naming a dynamic range with blanks

I have a range/list with values per row. Some of the rows are blank.
I want to name the range, and the range should reach the last value (nonblank cell).
So if any cells below the range that become populated, then the range must expand to those cells, even if there are blanks between, like in scenario 2.
Do anyone have a suggestion to how to solve this?
Try below formula which work both for number and text strings.
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(IF(Sheet1!A:A<>"",ROW(Sheet1!A:A),0)))
If you are on Excel-365 then try-
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(FILTER(ROW(Sheet1!A:A),Sheet1!A:A<>"")))
If the non-blank entries in that column are numeric, you can use:
$M$5:INDEX($M:$M,MATCH(88^88,$M:$M))
where 88^88 is assumed to be larger than any numeric within the range.
If the non-blank entries in that column are non-numeric, and none of the blank entries are in fact null strings (""), you can use:
$M$5:INDEX($M:$M,MATCH("Ω",$M:$M))

Find common text within a range of cells(range containing blanks as well)

This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel

=ISNUMBER(SEARCH()) formula not working properly

Basically, im trying to search if values from column b is contained in cells on column a
I am currently using the formula
=ISNUMBER(SEARCH(B1,$A:$A))
and using it inside a conditional formatting to highlight the cells in column A that contains strings from column B. But it is not highlighting the correct cells
any advice?
Problem is that your ISNUMBER(SEARCH(…. formula is returning an array of values {FALSE;TRUE;FALSE;FALSE;...} one return for each item in within_text. You need to know if any of those items match.
So, with your formula, consider the array formula modification
=OR(ISNUMBER(SEARCH(B1,$A:$A)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
If you don't like to use the CSE entry method, you could use this formula which will return zero for no matches, or be non-zero for any matches:
=SUMPRODUCT(-ISNUMBER(SEARCH(B1,$A:$A)))
Excel's SEARCH function is used to find the position of one string within another string. Generally you use it like this:
=SEARCH("String A", "A Longer String Containing String A")
This will return the character index where first string starts within the second string, which in this case would be 28.
What you really need is a VLOOKUP. Since you're doing a textual search (substring), you need your range to be of text type instead of number.
You should do the following:
Add an extra column to the right of Column A and use TEXT function to convert entries to textual form:
=TEXT(A1, "#")
Now you can use VLOOKUP to perform a substring-match in this textual range. VLOOKUP supports wildcards when you do not ask it to perform an exact match (4th argument should be FALSE). Here is your formula then:
=VLOOKUP("*" & C1 & "*",$B:$B,1,FALSE)
Note that I have passed column B (textual column) as the lookup range, whereas C1 is the cell containing the text that you want to search.
This method also has the additional advantage that it returns the actual matched entry from the range so you don't have to find it manually.
Once you have your results, you can apply conditional formatting to it.
Highlight column A (or the relevant range in column A starting cell A1) with the first cell (which is A1 in this case) as the active cell, use the following formula as the conditional formatting rule:
=(SEARCH($B1,$A1)*(LEN($B1)>0))>0
The logic is to first search the given sub-string from the main string, then multiple the result by LEN($B1)>0 to exclude the result of 1 returned for blank cells in column B.
Note: Conditional Formatting works in array fashion so even though the formula only looks at values in the first row of the range, as long as you use the relative (or in some cases absolute) cell references correctly and highlight the result range correctly before setting up the rule, the rule will be applied across in the same way as for the first row of the array as demonstrated in this example.

IF Values match return true

I am trying to get some code working but when I change a target cell into a range of cells I get an error #VALUE!
this code works
=IF(AND(A1=Sheet2!A2,B1=Sheet2!B2),"TRUE","FALSE")
but if I add a range I get #VALUE! Error
=IF(AND(A1=Sheet2!A2:A10,B1=Sheet2!B2:B10),"TRUE","FALSE")
Update : Here is an example of what I am trying to achieve
Any help would be much appreciated
Many Thanks,
And
Different approach from your logic statement. Instead it looks through your table and match the name with the row and the column with the date selected and the pulls the value at that location.
=INDEX($B$7:$G$8,MATCH($B3,$A$7:$A$8,0),MATCH(C$1,$B$6:$G$6,0))
IMPORTANT: The names in you B3:B4 area have to be unique and spelled identical to your A7:A8 area. That included trailing or leading spaces that you may accidentally drop in.
Adjust reference ranges to match your need if tables are on different sheets of your workbook.
THIS IS AN ARRAY FORMULA - Hit Ctrl+Shift+Enter While still in the formula bar
=INDEX(B2:B10,SMALL(IF(A2:A10=A1,IF(B2:B10="ONCALL",ROW(A2:A10)-1)),1))
=INDEX(B2:B10, - Look through B2:B10 and return the row number calulcaulated by:
SMALL(IF(A2:A10=A1,
IF(B2:B10="ONCALL",
ROW(A2:A10)-1)),1))
This is building an array of row numbers minus 1 where both IF statements are true (Date matches and "ONCALL" present), SMALL then returns the nth value in ascending order - I have asked for the 1st match (or the smallest row number) which INDEX then uses to return the result.

Adding a value to a SUM

I have a row with multiple blank values. I want the answer to be "" if all values are blank. If any of the cells contain a value, I would like to take the SUM of those cells, and add 10 to it. The formula I am using is below, and it always displays the answer as "10", even if all cells are blank. Please help.
=IF(ISBLANK(A1:D1),"",SUM(A1:D1)+10)
ISBLANK() only works on a single cell. You want to use COUNTA() instead.
Counts the number of cells in a range that are not empty
=IF(COUNTA(A1:D1) = 0,"",SUM(A1:D1)+10)

Resources