Return value of last populated cell in variable range - excel

Into column D, I'd like to copy the value from the last cell with data in columns E up until the column with the header "DETAIL". There might be anywhere from 2 to 15 columns from E until the column with that header, so that's where I'm stuck. So to be clear, an example:
A B C D E F G H DETAIL
1 x x x a b c d x
2 x x x x
3 x x x c b a x
3 x x x d c x
Should fill column D like so:
A B C D E F G H DETAIL
1 x x x d a b c d x
2 x x x x
3 x x x a c b a x
3 x x x c d c x
I don't mind handling this with a formula (which I couldn't come up with) or programmatically.

Create a dynamic named range by pressing CtrlF3 to bring up the Name Manager, click New, name the range something (I chose MyRange) and then use this formula to define it (Note you may need to change the Sheet name):
=Sheet1!E2:INDEX(Sheet1!2:2,MATCH("Detail",Sheet1!$1:$1,0)-1)
Then, in cell D2 and copied down, use this formula (I did not use IFERROR so that it would be backwards compatible):
=IF(COUNTA(MyRange),INDEX(MyRange,MATCH(REPT("z",255),MyRange)),"")
Here are the results (highlighted) using your provided sample data:

Please try:
=IFERROR(INDEX(F2:T2,,MATCH("zzzzzz",F2:T2)),"")
in D2 and copied down to suit.

Try using LOOKUP:
=IFERROR(LOOKUP(9^99,SEARCH("*",E1:H1),E1:H1),"")
SEARCH("*",E1:H1) returns a number when it matches any character and an error when the cell is blank. LOOKUP then returns the contents of the cells of the last number smaller than 9^99 in the array generated by SEARCH.
For example, in the first row, SEARCH("*",E1:H1) returns {1,1,1,1} so that LOOKUP returns the last 1, being d.
In the third row, SEARCH("*",E3:H3) returns {1, 1, 1, #VALUE!} and LOOKUP returns the last 1, which is a here.
This formula will work with numbers and text alike. The downside is that it is considered slower than INDEX/MATCH. On the other hand, you can modify the INDEX/MATCH to work with numbers, or modify it to work for both but becomes an array formula:
=IFERROR(INDEX(E1:H1,,MATCH(1,SEARCH("*",E1:H1))),"")
[Works with Ctrl+Shift+Enter, otherwise returns an empty cell with Enter alone]

Related

How to return row based on all searched instances of a value in a Table excel

I have a very large table with repeating values based off of a ID column. I'm after a function/combination of excel functions that would work to return the ID number where all instances of a searched value are met?
I dont have access to the "Filter" function so im looking for an alternative to this.
E.g, I wish to find all instances of F in the table. From here the function should return the row/associated "ID"
This would then output 2,4,25 where the matches in the table occur
ID
B
C
D
...
BB
BC
SEARCH
F
1
A
B
C
D
E
G
2
D
E
G
F
G
S
3
T
V
A
K
H
E
4
Y
F
J
N
R
K
5
I
O
W
H
X
Z
...
25
T
K
Q
E
H
F
array formula:
=IFERROR(INDEX(A:A,SMALL(IF(B$1:G$500="F",ROW($1:$500)),ROW(A1))),"")
You can try creating an extra column at the end and use this formula in each cell down that column. Make sure your "Search Cell" remains same in the formula though:
Drag this down from first cell down to all rows but make sure the search cell remains same. i.e. B1 in my example. I have added a last extra column H in my example to do this calculaton and the result:
=IF(IFERROR(MATCH(B1,B2:G2,0),"")<>"",A2,"")

Is there a formula that inputs on nth row of column A by reading what's in column F and/or D on their congruent rows?

I'm very new to excel programming. Currently I'm working on an excel worksheet and I need a formula that inputs on nth row of column A by reading what's in column F and/or D on their congruent rows. So far I have something like:
=IF(AND(D:ROW(n)=0,F:ROW(n)="x"),A:ROW(n)="e",IF(D:ROW(n)=0,"N","X"))
e.g.
A B C D E F
1 e 0 x
2 N 0
3 X 2
Put this in A1:
=IF(D1 = 0,IF(F1="x","e","N"),"X")
And copy down.
The references are Relative, so as the formula is copy/dragged down they will change on their own.

How to sort 3 columns of data in excel

I'm using Microsoft Excel 2011 on a Mac, and I need help sorting 2200 rows of data.
Basically, what I want to do is to sort the Type column, while keeping its corresponding data beside it after the type is shifted.
I would like all the type A's, B's, and C's to be in order, and have their adjacent data from experiment 1 and 2 follow to the new position once sorted.
Each data group is separated by a few empty rows.
Here's a small example of what my data looks like:
Type EXPERIMENT 1 EXPERIMENT 2
A A F
F R
S S
E G
B Y A
A A
S H
F
A A E
D F
F S
E
Y
A F H
R G
E A
D F
Y W
S E
S
C F S
D D
S U
F J
Y
T
And this is what I want:
Type EXPERIMENT 1 EXPERIMENT 2
A A F
F R
S S
E G
A A E
D F
F S
E
Y
A F H
R G
E A
D F
Y W
S E
S
B Y A
A A
S H
F
C F S
D D
S U
F J
Y
T
In an unused column to the right (aka Helper column) put this formula into the second row.
=VLOOKUP("zzz",A$1:A2,1)&TEXT(COUNTIF(A$1:A2,VLOOKUP("zzz",A$1:A2,1)),"0000")
... and fill down as necessary. Select all of the columns and sort with the Helper column as the primary sort key. The results from your sample should mirror the following.
                 
Additional formulas can be provided if you need sorting key criteria on the Experiment x columns. Show what you've tried together with some example of the results expected and additional assistance will no doubt be offered.
It seems to me it would be easy to sort if you would concatenate each data set into a row. Type goes in column A; Exp 1 into one cell in column B; Exp 2 into one cell in column C. Then the sort is simple. Otherwise you'll require a complicated macro. You can always parse it out later if required.
To concatenate you'll need to:
Save as new workbook first to avoid changing your original data
Insert a row between the headers and the first data
Put the formulas indicated into row 2 and copy down
Copy and PasteSpecial as values
Sort by column D
Delete all rows that are false
Now your sorting will be easy.
Edit: fixed my formulas to line up with true column.

Excel Array Function to Sum a number of COUNTIF statements

I'm having difficulty phrasing this intelligently, but I'll try the long way -- I need a function that assigns a 1 or 0 depending on whether the row has an "x" in one of four previous columns and then sums all those assigned values.
In other words, imagine the following formula is in E2 and autofills down for any given number of rows.
=IF(COUNTIF(A2:D2, "x")>=1, 1, 0))
I want to write an array function in F2 that would do the equivalent of summing all the values in column E (but don't reference column E).
Sum of ...
=IF(COUNTIF(A2:D2, "x")>=1, 1, 0))
=IF(COUNTIF(A3:D3, "x")>=1, 1, 0))
=IF(COUNTIF(A4:D4, "x")>=1, 1, 0))
=IF(COUNTIF(A5:D5, "x")>=1, 1, 0))
...for all of column A through D
Sample Data:
A B C D
20-Sep 20-Sep 21-Sep 21-Sep
x x
x x
x
x
x
x
x
x x
x
The formula should return the value 9. There are 9 rows that have an "x" between the columns A and D.
Try this out:
=SUM(--(MMULT(--(A2:D5="x"),{1;1;1;1})>0))
Commit normally (array entry will neither help nor hurt). If your production range is wider than 4 columns expand the {1;1;1;1} array.
Also works:
=SUM(N(MMULT(N(A2:D5="x"),{1;1;1;1})>0))

Excel get average of a result of index+match function, see details

So I have:
A B C down here i want to get an average
like this:
v 1 a (*1) filter col "C" for what i have in row for col C, in this case "a", then filter col A for what I have in my row for col A, then all those rows must be counted, then sum them and then: sum/count
v 2 a
y 3 a
y 7 a
y 3 a
v 2 b
y 4 b
v 2 b
y 7 b
thanks
You want COUNTIFS and SUMIFS (check Excel help for the params)
Assuming your first row starts on A1:
=SUMIFS($B$1:$B$9,$C$1:$C$9,C1,$A$1:$A$9,A1) / COUNTIFS($C$1:$C$9,C1,$A$1:$A$9,A1)

Resources