Excel: Dividing comma separated single cell numbers - excel

I have a string of numbers in a single Excel cell separated by commas, e.g. A2 = "4,3,2,7". I want a formula to be able to divide those number by 2 in cell B2, e.g. B2 = "2,1,1,3" (odd numbers should round down rather than up)
The formula needs to be able to account for:
- smaller or larger string of numbers
- for both single and double digit numbers
- numbers that are even or odd
- no VBA
- formula can use multiple columns but not the delimited text to columns feature (due to cell location)
I was able to get a formula to sum the string of numbers in A2 (4,3,2,7 = 16) but not able to divide by 2. My formula to sum the string is below. Any help is appreciated, thanks!
{=SUM(IF(ISERR(VALUE(MID(A2,ROW($A$1:OFFSET($A$1,LEN(A2)-1,0‌​)),1))),0,VALUE(MID(‌​A2,ROW($A$1:OFFSET($‌​A$1,LEN(A2)-1,0)),1)‌​)))}

In your example, use this formula into cell B1:
=SUBSTITUTE(SUBSTITUTE(A1,",","000")/2,"000",",")
Then result will be like this:
| A | B |
+---------+---------+
1| 4,2,6,8 | 2,1,3,4 |
2|

Well, This is my second attempt to solve(I hope) your problem. If your string is in cell A2, then put this code inot cell B2:
=LEFT(IFERROR(ROUNDDOWN(MID(A2,1,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,3,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,5,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,7,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,9,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,11,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,13,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,15,1)/2,0),""),LEN(A2))
It can be worked with up to 8 number string, as well as odd numbers.
Update
This formula can handle double digit numbers but it supports only from 1 to 4 string numbers(e.g. (25,5,36,48)):
=LEFT(IFERROR(ROUNDDOWN(MID(A2,1,IFERROR(SEARCH(",",A2,1)-1,LEN(A2)))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,1)+1)-SEARCH(",",A2,1)-1,LEN(A2)-SEARCH(",",A2,1)))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)-SEARCH(",",A2,SEARCH(",",A2,1)+1)-1,LEN(A2)-SEARCH(",",A2,SEARCH(",",A2,1))))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)+1)-SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)-1,LEN(A2)-SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)))/2,0),""),LEN(A2))

Related

Excel printing a specific number in a row subject to other columns

I have an excel file with 3 columns and 100 thousand rows. My goal is to print the number of column A, where the number in column C is the maximum and the number in column B is higher or equal to 0.9. Like this example:
-----+------+-----
A | B | C
-----+------+-----
1 | 0.9 | 130
2 | 0 | 200
3 | 0.95 | 90
In this example for example it should print '1' since column 1 and 3 are higher than 0.9 but 1 is higher than 3 in column C. Anyway to do this in excel?
Assuming your data in column C is positive (or at least, that the maximum value is positive), you can use this array formula:
= INDEX(A:A,MATCH(LARGE(((B:B>=0.9)+0)*(C:C),1),((B:B>=0.9)+0)*(C:C),0))
Note this is an array formula, so you must press Ctrl+Shift+Enter after typing in the formula.
This gets pretty ugly since there is no =MAXIFS() formula. Instead, an array formula will do the trick:
=SUMIFS(A1:A3, C1:C3,MAX(IF(B1:B3>=0.9, C1:C3, 0)), B1:B3,">=.9")
Hit Ctrl+Shift+Enter when entering that so Excel will interpret as an array formula.
The Sumifs() here isn't summing more than one value so no worries there. We are grabbing the value from A1:A3 where C1:C3 is equal to the MAX() of that column where B1:B3 is greater than or equal to .9. Which solves that max() issue. And then we are then only allowing selection A1:A3 where B1:B3 is greater than or equal to .9.
It's not pretty, and it requires us to check that >=.9 condition twice, but it does the job.
Try using this array formula =SUMPRODUCT(INDEX(A2:A20,MATCH(MAX(--($B$2:$B$20>=0.9)*C2:C20),--($B$2:$B$20>=0.9)*C2:C20,0),1)) in cell D2. Confirm it with CTRL+SHIFT+ENTER.
This is the array formula (means you have to click Ctrl + Shift + Enter altogether) what I came up with:
=INDEX(A:C,MATCH(MAX(--(B:B>=0.9)*(C:C)),(B:B>=0.9)*(C:C),0),1)
Please note that I used the whole column but I will suggest to only use the ranges that are needed for faster speed.

COUNTIF range does not equal range

The data I'm looking to get is something like this:
+----------+-------+
| Location | Count |
+----------+-------+
| Jungle | 2 |
| Ocean | 4 |
| Other | 2 |
+----------+-------+
The formula for count should look in the data range and if a cell's data does not equal any of the cell data in the rest of the location column (Jungle, Ocean) it should add that to the count. It should exclude blanks.
This is the formula I tried:
=COUNTIF(A1:H6,"<>"&E11:E12)
Here is my example sheet: https://docs.google.com/spreadsheets/d/1YbqEwa3olEXMcmU-UORfe7jwyK_-AXDomp1t5iTVUaU/edit?usp=sharing
Where am I going wrong? There are 7 other instances of colours not Green or Blue therefore I would expect this result to be output. I haven't put anything in about ignoring spaces so I would expect the result to count blanks too, but I get 0.
Don't use & - this would join E11 and E12 together so you would be looking for greenblue. You would need a COUNTIFS to get the three conditions
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")
Here is a more general way of doing it
=COUNTA(A1:H6)-SUMPRODUCT(COUNTIF(A1:H6,E11:E12))
See this useful reference
The COUNTIFS formula is your friend here. This formula should work for that cell:
=COUNTIFS(A1:H6,"<>"&E11,A1:H6,"<>"&E12,A1:H6,"<>")
The problem with a 'does not equal OR does not equal' is that when it is not equal to one, it could be equal to the other and vice-versa. Additionally, you range to count from is 2 dimensional so you cannot use rows of criteria. Use SUMPRODUCT and individual criteria multiplied against each other.
=SUMPRODUCT((A1:H6<>"")*(A1:H6<>E11)*(A1:H6<>E12))
Any of those three conditions that is not true is considered zero. Anything multiplied by zero is zero. 1 x 1 x 1 is 1.
For large numbers of exclusions, you will want to use an array formula (with CSE) to count them and then subtract that total from a COUNTA total of the entire range.
=COUNTA(A1:H6)-SUM(COUNTIF(A1:H6,E11:E15))

Swapping street names

I have a list of street intersections in excel. Of course it reads S 74th St / Rogers Ave as being different from Rogers Ave / S 74th St. I am trying to swap the cells on the columns so that intersections like that all end up looking the same. I have broken them down into two columns and having been trying the iferror/index/match functions but obviously not doing it right. If there is a macro I could write, that would be ideal. Any ideas?
Assuming your data always appears in a single Cell, in the format "[Street 1] / [Street 2]", this can be done with some helper columns.
First in column B, use the following formula, which will pull out the left name from the intersection:
=LEFT(A1,SEARCH(" / ",A1)-1)
Then do a similar thing in column C:
=RIGHT(A1,LEN(A1)-SEARCH(" / ",A1)-2)
Then, in column D, you will create a new text string showing the intersection, sorted [sort of] alphabetically by the first 4 characters of each road. You can do this as follows:
First, consider the below formula, which picks up the ASCII character value of the first 4 characters of the word found in B1:
=SUM(CODE(MID(LOWER(B1),{1,2,3,4},1)))
This creates a single number which equals the sum of the specific code for each character. We can use that to sort the priority of one cell over another, by comparing with the sum of the same formula for the cell in C1, like so:
=SUM(CODE(MID(LOWER(B1),{1,2,3,4},1)))>SUM(CODE(MID(LOWER(C1),{1,2,3,4},1)))
This will show TRUE if the sum of those codes in B1 is bigger than the sum of those codes in C1. Put this formula in D1 and copy down.
Finally, recreate your ordered string as follows, in column E:
=IF(D1,B1&" / "&C1,C1&" / "&B1)
Now this can be used as a column of ordered data, which should eliminate matches in the streets [assuming no streets have the same 4 characters as any other, and no duplicate streets start differently - ie 5 Ave vs 5th Ave].

Excel, sum range split

I have a google spreadsheet and I want calculate to some data...
I want to sum the splits in a range
1 | A1 |
2 | 1Q1 |
3 | 3Q2 |
4 | 5Q7 |
I need the sum of the integers after the letter "Q" so in the example above I would get 1+2+7=10
This formula will do it all in one, just set the range in the formula , ie A2:A4
=SUM(VALUE((RIGHT(A2:A4,LEN(A2:A4)-FIND("Q",A2:A4,1)))))
Press CTRL+SHIFT+ENTER to enter the array formula.
You can use the function VALUE(RIGHT(text)) which will give you back the number value of the rightmost character in the string. Then use those values in your sum.
Assuming that the 3rd character is the number, you could try something like
=VALUE(MID(A:A,3,len(A:A)))
in column B
then sum that like this (for the 1st 3 rows):
=SUM(B1:B3)

Excel: Matching the closest date from range of dates

I'm trying to display the header of the column that its cell that contains a date, is the closest (out of 3 other cells with dates, B2:D2) to the a specific cell (A2)
So here's my sheet:
A B C D
1 | T1 | T2 | T3 | T4 |
2 | 5/1/2013 | 5/31/2013 | 2/5/2013 | 3/2/2013 |
A2 = a date.
B2:D2 = 3 dates, can also be blank
I've tried using the following array formula that I found online:
=IF(COUNT($B2:$D2)>0,INDEX($B$1:$D$1,MATCH(MIN(ABS($B2:$D2-$A2)),ABS($B2:$D2-$A2),0)),"")
But it sometimes when there is only one or two dates, it gives me the wrong header. I would also like to avoid using array formulas, but couldn't convert it to a regular one.
Would highly appreciate assistance on this matter
Can you give an instance were the array formula you are using isn't working ? It worked for the cases I tried.
You can avoid using the array formula if you are prepared to have another row with the difference in the dates and your date cell A2.
Push your rows down one row, so the headings are on row 2 and the dates on row 3 and enter the following formula across row 1, starting at cell B1
=ABS(B3-$A$3)
Drag this across and enter the following HLOOKUP to get your header row
=HLOOKUP(MIN(B1:D1),B1:D3,2,FALSE)
if you can't move your rows down for some reason you can use a combination of MATCH and INDEX (which is slower) . If you were to put the difference function =ABS(B2-$A$2) across row 7 the formula would be
=INDEX(B1:D1,1,MATCH(MIN(B7:D7),B7:D7,0))
Okay so the answer was fairly simple.
I went back to the sheet to investigate the scenarios in which this happens.
It seems that when A2 is blank (= no date to make the comparison) it just gives out the only date available from B2:D2.
By simply adding another condition to the IF statemented that would work only if A2 has a value resolved the issue. So we're checking if both A2 and B2:D2 has values in them (with B2:D2 needs to be at least one:
=IF(AND(COUNT($B2:$D2)>0,$A2>0),......)
and here is the full formula
=IF(AND(COUNT($B2:$D2)>0,$A2>0),INDEX($B$1:$D$1,MATCH(MIN(ABS($B2:$D2-$A2)),ABS($B2:$D2-$A2),0)),"")
Thanks for making me go back to the investigate! :D
For a non-array alternative, you could try:
=LOOKUP(2,1/FREQUENCY(0,ABS(B2:D2-A2)),B$1:D$1)
in place of the INDEX(...) part of the formula.

Resources