How to sum +1 if value exists - excel

Hard to explain and english is not my native language, but i'll do my best. I have a cell with a CONCATENATE formula which creates a "code" value to identify different articles. The CONCATENATE formula is getting the values from 6 different cells. I need the 6th cell to sum +1 if the value of the other 5 cells already exist.
For example:
1
AAA
2
BBB
3
CCC
4
DDD
5
EEE
6
NNN (where NNN is a specific 3 characters number)
CONCATENATE creates the AAABBBCCCDDDEEENNN code. For the first article, it will be AAABBBCCCDDDEEE001. Then, if I create another article with AAABBBCCCDDDEEE, I want to 6th cell to fill up with 002, since 001 already exists.
Is that possible?
Thanks in advance.

If you enter '001 for the first cell in your 6th column, you can use this formula in the cell below it and copy it for all the cells below.
=IF(CONCATENATE(B2,C2,D2,E2,F2)=CONCATENATE(B1,C1,D1,E1,F1),CONCATENATE("00",G1+1),"001")

Related

How to SELECT N values ABOVE and BELOW from specific value

If I have a table:
Column A
Column B
Column C
1
Jane
10
2
Stewe
9
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
10
Carol
1
I would like to SELECT 3 rows above and below WHERE Column B = someValue .
IF query SELECT * WHERE Column B = "Andrew" result should look like:
Column A
Column B
Column C
3
John
8
4
Mike
7
5
Luke
6
6
Andrew
5
7
Carl
4
8
Sasha
3
9
Ariel
2
I know how to select one row, but cant understand how to select such range.
Thanks for ideas!
You can limit and offset inside your QUERY():
=QUERY(A1:C,"limit "&2+MIN(5,MATCH(D1,B:B,0))&" offset "&MAX(0,MATCH(D1,B:B,0)-5))
Well, this was fun...
If 3 above or below are not available then blank... rolling data around is a different proposition.
Below the image is the list of formulae used.
So, per cell not including the data validation that is based on cells B2:B11
A14 and dragged down:
=IFERROR(INDEX($A$2:$A$11,MATCH(B14,$B$2:$B$11,0)),"")
C14 and dragged down:
=IFERROR(INDEX($C$2:$C$11,MATCH(B14,$B$2:$B$11,0)),"")
Cells B14 through B20:
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=3,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-3)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=2,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-2)),"")
=IFERROR(IF(MATCH(B$17,$B$2:$B$11,0)=1,NA(),INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)-1)),"")
=E2
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+1),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+2),"")
=IFERROR(INDEX($B$2:$B$11,MATCH(B$17,$B$2:$B$11,0)+3),"")
In Excel 365, you could try:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
In Google sheets, on the other hand, the formula would be:
=INDEX(A:C,MAX(2,MATCH(D2,B:B,0)-3),0):INDEX(A:C,MIN(COUNTA(B:B),MATCH(D2,B:B,0)+3),0)
(spot the difference).
Excel
Google Sheets
This should produce what you want in all cases:
=IFERROR(FILTER(A2:C,B2:B<>"",ROW(A2:A)>=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)-3,ROW(A2:A)<=VLOOKUP("Andrew",{B2:B,ROW(B2:B)},2,FALSE)+3))
Of course, you can replace the two instances of "Andrew" with a cell reference (one where you type a changeable name).
This just looks up the row in a curly-bracket array formed from the names and row numbers and uses FILTER to keep results to rows between +/-3 rows of where the target name is found. If you choose the first name (or any other name), you won't get an error; because even if the target name were on Row 1 and the formula goes looking for anything "greater than or equal to 1 minus 3, all rows will be greater than a negative number. Same on the high end. You just won't get a full seven names if there aren't at least three other rows prior to or after the target row.
this not the best solution but it will work , you can use a helper column 'D' that contains the following formula =if(countif(INDIRECT("B"&ROW()+3&":"&"B"&ROW()-3),"Andrew")>0,TRUE,FASLE)
and u can query from here like this SELECT * WHERE Column D = TRUE

divide duplicate values by the number of duplicates for that value

I want to write a VBA code or excel formula that will divide duplicate values by the number of duplicates for that value. For example
A- 6
B- 8
C- 3
D- 4
F- 5
A- 8
A- 4
The code would add 6+8+4 and then divide by 3. It would replace each current value for A with 6.
Meh...
Say column A contains your letters, Column B contains your numbers, and row 1 is a header row. Enter this formula in cell C2 and pull it down:
=B2/COUNTIF(A:A,A2)
You can use an Averageif formula
=AVERAGEIF(A:A,A2,B:B)

Convert some cells in a column from date format to text

Given a column like this:
Column A
1 4
2 Blank
3 Blank
4 3
5 blank
6 2NDF
7 Blank
8 blank
9 1/2/2014 <-- Date value I need to change to a text value: "1-2"
10 blank
11 5/1/2014 <-- Date value I need to change to a text value: "5-1"
12 blank
...
I need to find a way to programmatically change each cell that contains a date value like in rows 9 and 11 into a text value the equivalent of the numeric month followed by a dash follwed by a numeric day. I have 24,000 rows. Doing a find and replace is not practical. I cannot change the format of the entire column because rows like 1 and 4 get converted and I don't want those to get converted.
Create a new column B and use the function
=IF(NOT(ISERROR(DATEVALUE(A1))),MONTH(DATEVALUE(A1))&"-"&DAY(DATEVALUE(A1)),A1)
OK, I achieved the result I wanted by splitting out three "if" tests (similar to what Brett suggested) into 3 additional columns. Each column had its separate "if" test and built on the column before it. Here are the if tests:
=IF(N5>40000,MONTH(N5)&"-"&DAY(N5),N5) # sets format I want and skip cells that are low integers and not dates
=IF(O5=0,"",O5) # Sets cells with "0" in them to blank
=IF(ISERROR(P5),N5,P5) # fixes cells that were originally text and that produced errors
Given that in the OP the data seems to be in ColumnA starting in Row1 a single formula such as:
=IF(OR(A1<40000,ISTEXT(A1)),A1,MONTH(A1)&"-"&DAY(A1))
and copied down would seem adequate.

Find value from one cell, copy value from cell near to that cell and paste it to another sheet

I have 2 sheets with different values. I need to find a value from one cell.sheet1 in sheet2 and copy value from nextcell_in_the_same_row.sheet1 to nextcell_in_the_same_row.sheet2.
It is very difficult to explain let look at the example bellow.
E.g.
Before
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa
2 ada
3 cca
4 ccc
After
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa *need to find value in the first sheet and copy value from B2 because aaa in A1*
2 ada *value does not exist in the first sheet so copy nothing*
3 cca *not need to copy because no value in the first sheet*
4 ccc *need to copy the value from B3*
Thank you so much!
Use a VLOOKUP along with an IFERROR.
=IFERROR(VLOOKUP(A1, Sheet1!A:B, 2, 0), "")
This will do what you described (well described, by the way!) in your question. Drag the formula down in Sheet2 till the bottom.
VLOOKUP takes the value of A1 in sheet 2 (no sheet reference because the value is in the same sheet as the formula) and looks it up in column A of Sheet1.
It returns the second value (hence why 2) of the table selected in the formula (column A is 1, column B is 2).
The 0 tells the VLOOKUP to look for exact matches. You don't need approximate match here.
And IFFERROR is there in case VLOOKUP doesn't find anything (like with ada) and instead of giving #N/A, returns an empty cell, "".

Return value of last match

I need a formula to return the value of Data for the last match of "Text". Row number is also acceptable. Macro is NOT acceptable. Name column is unsorted and cannot be sorted!
Only column "Name" is used as lookup value. I would rather use a/multiple helper column(s) instead of an array formula.
Row Name Data
1 Joe 10
2 Tom 20
3 Eva 30
4 Adam 40
5 Tom 21
LARGE only works with numbers, and VLOOKUP only returns the first match. LOOKUP only works sometimes, so its out too.
So if I wanted the last match for "Tom" then it should return "21".
Array formulas could be avoided with a helper column.
Suppose to have in F1 the name to match (i.e. Tom)
In the helper column row C2 enter
=IF(A2<>$F$1,0,row())
Then copy the formulas along your data.
Now the column C contains 0 for the unmatched names and the row number for the matched ones. Maxing the column yield the row of the solution.
Now the result is simple a matter of using the correct offset with the function offset:
=OFFSET(B1,max(C:C)-1,0)
PS: my copy of excel is in italian, so I can't test this english translaction of the formulas.
I think it's the easiest way to make it.
=LOOKUP("Tom";A2:B7)
Create a column with an array formula (enter it with Ctrl+Shift+Enter):
=VLOOKUP(MAX(IF($B$2:$B$6=B2, $A$2:A$6, 0)), $A$2:$C$6, 3, FALSE)
To make sure you did it right, click on the cell, and the formula should be shown encased in curly brackets ({}).
Note: This assumes that "Row" is in A1.
I have come up with a solution, but it requires that numbers in Data are concurrent, like so
Name Data
Joe 1
Tom 1
Eva 1
Adam 1
Tom 2
Tom 3
Eva 2
But thats okay, since that my data looks like that anyway. So if Name is used before then it must be the old highest +1 aka concurrent.
Name is A1 and Data is B1, and this formula goes into C2:
FLOOR(SQRT(2*SUMIF(A2:A7,A2,B2:B7)),1)

Resources