Find name of the last cell with data in a row - excel

I've searched for an answer, but it seems that I can only find VBA-based solutions, which appear no longer be an option in Excel 2008.
I'm trying to return the name of the last cell in a row that contains data. It looks like this:
+===========================================================+
A / B / C / D / E (columns)
+===========================================================+
1 || [Formula] / 3 / 4 / 5 / [blank]
2 || [Formula] / 7 / 8 / [blank] / [blank]
3 || [Formula] / 9 / 10 / 11 / 12
(rows)
+===========================================================+
and the end result would look like this:
+===========================================================+
A / B / C / D / E (columns)
+===========================================================+
1 || D1 / 3 / 4 / 5 /
2 || C2 / 7 / 8 / /
3 || E3 / 9 / 10 / 11 / 12
(rows)
+===========================================================+

It looks like your data is sorted from left to right.
If it is, you could start with something like =MATCH(MAX(C4:K4);C4:K4) to retrieve the column index of the last cell (max) of the row. From there, it's easy to buid the address:
=ADDRESS(ROW();MATCH(MAX(C1:K1);C1:K1);4)
Edit: combining ADDRESS with COUNT or COUNTA (great idea from Dustin Geile) does not require the items to be sorted:
=ADDRESS(ROW();COLUMN()+COUNT(B1:Z1);4)

=CHAR(COUNTA(B1:ZZ1) + 65) & ROW()

You can try this arrayformula:
{=ADDRESS(ROW(B2),MAX(IF(ISEMPTY(B2:H2),0,COLUMN(B2:H2))))}
Validate with CtrlShiftEnter

If you are looking for the last cell with data, you can write a quick function and place it in a VBA module in your workbook.
Public Function LastCell(inRange as Range)
LastCell = inRange.End(XlToRight).Address
End Function
Or just omit the '.Address' if you want to get a range object pointing to the cell.
You can then use it in a formula like...
=LastCell(A1)
Regards
Ray

Related

Increment a number within a formula by 2 each time

As in this image:
I have the following formula in merged cellset F229:F231, which works correctly:
=OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)-3),)
This pulls data from another worksheet - in this case the value 73.0 is pulled (there are similar formulas in the cell range H229 to M231.
Essentially I want the -3 part at the end of above OFFSET formula to increment by two each time I copy and paste the three row set. So in the merged cellset of F232 - F234 it would be -5 and in the next one it would be -7, then -9 etc.
It's a bit of a hack but this would result in the correct data being pulled. This is not a work spreadsheet, just a personal log to record my food etc so doesn't have to be ideal.
Change -3 to +2*Row()/3 + c, where c is a modifier to ensure that your first row lines up
For example, if the first row is line 4, and you want the value to be 2:
- 2 * Row() / 3 + c
- 2 * 4 / 3 + c
- 8 / 3 + c
- 2.666 + c
c = - 1/3
- 2.666 - 1/3
- 3
- 2 * Row() / 3 - 1/3
Then, when you copy it down to Row 7:
- 2 * Row() / 3 - 1/3
- 2 * 7 / 3 - 1/3
- 14 / 3 - 1/3
- 4.666 / 3 - 1/3
- 5
Use one of the following formula for your counter starting at -3 and changing by -2 every three rows. You can either start using row A1 or you can reference your current cell and make some adjustments to the formula to achieve the same result.
=-3-2*(ROUNDUP(ROW(A1)/3,0)-1)
or
=-3-2*(ROUNDDOWN((ROW(G229)-ROW($G$229))/3,0))
both will work for generating the number you are looking for
Your final formula might look like:
=OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)+(-3-2*(ROUNDUP(ROW(A1)/3,0)-1))),)

Excel | Index Match |

I require your assistance on the following:
Lets say we got 3 different groups: (A,B,C)
And we have a few value ranges within each group:
(Eg. A has 0 - 100, 101 - 200 while B has 0 - 200, 201 - 400 and C has 0 - 300, 301 - 600.)
At the end, for each group that falls under whatever range they have, they will be assigned a final number.
(Eg.
[A,95] = 0.5 / [A,101] = 1.0
[B,95] = 1.5 / [B,205] = 3.0
[C,95] = 4.5 / [C,308] = 6.0)
Currently i have my index match formula as follows:
"=INDEX(finalnumber!F2:F29,MATCH(C11&C25,Group!A2:A29&valuerange!D2:D29,0))"
I keep getting a #N/A response.
I have also created an array table as follows:
enter image description here
Group Range Final Number
A 0 - 100 0.50
A 101 - 200 1.00
B 0 - 200 1.50
B 201 - 400 3.00
C 0 - 300 4.50
C 301 - 600 6.00
Pls help! Many thanks in advance!
You can use the following (you will need to tailor to your layout). I have assumed A and 95, for example, are in separate cells as you concatenate cells in your formula to do your lookup.
=IF(AND(ISERROR(INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0))),INDEX(A:A,COUNTA(A:A)+1)=F2,G2>=1*LEFT(INDEX(B:B,COUNTA(A:A)+1),FIND("-",INDEX(B:B,COUNTA(A:A)+1))-1),G2<=1*RIGHT(INDEX(B:B,COUNTA(A:A)+1),LEN(INDEX(B:B,COUNTA(A:A)+1)) - FIND("-",INDEX(B:B,COUNTA(A:A)+1)))),INDEX(C:C,COUNTA(A:A)+1),INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0)))
This is entered as an array formula with Ctrl+ Shift+ Enter
Formulas in helper cells (to keep overall formula more legible):
H2 is =MATCH(F2,A:A,0) ' finds the first match for the letter e.g. A
I2 is =MAX(IF(A:A=F2,ROW(A:A)-ROW(INDEX(A:A,1,1))+1)) ' finds the last match for the letter e.g. A. This is entered with Ctrl+ Shift+ Enter i.e. an array formula.
Data layout
Example run:
Notes:
You might want to wrap the whole thing in an IFERROR( formula, "") to hide any not found error messages.
I'm unclear why you require four separate worksheets for this operation. For simplicity in demonstrating, I've put your lookup table on the same worksheet as the values to lookup.
=SUMPRODUCT(I$2:I$7, (G$2:G$7=LEFT(A2))*(--REPLACE(H$2:H$7, FIND(" - ", H$2:H$7), 9, TEXT(,))<=--MID(A2, 3, 9))*
(--REPLACE(H$2:H$7, 1, FIND(" - ", H$2:H$7)+1, TEXT(,))>=--MID(A2, 3, 9)))

Average range between multiple unique number pairs in excel

Suppose I have the following data in exce l:
For each row, I want to know what the average range between each unique pair of variables is.
Is there a way to do this in one go, without having to manually calculate the range between every number pair?
Taking row one as an example, the unique pairs and their ranges are as follows:
8 - 5 = 3
8 - 6 = 2
6 - 5 = 1
The average range is (3 + 2 + 1)/3 = 2.
So, the output should be 2, but I want to know if there is a way to do this all in one formula
Paste the following array formula into cell D1 and drag down as far as necessary:
= SUM(ABS(A1:C1-TRANSPOSE(A1:C1)))/(COLUMNS(A1:C1)*(COLUMNS(A1:C1)-1))
(Obviously, you'll have to change the formula above to whatever your cell ranges are.)
Note this is an array formula, so you must press Ctrl+Shift+Enter on the keyboard when entering this formula rather than just Enter.
See below for a demonstration that this formula works.
As in the example in your question, the result for the first row is 2.
Second row:
10 - 1 = 9
3 - 1 = 2
10 - 3 = 7
(9+2+7)/3 = 18/3 = 6
Also note, this formula works for variable column ranges. (It doesn't just have to be 3 columns.) See below for an example with 4 columns. (The formula is in cell E1 and is evaluating over cell range A1:D1.)
8 - 2 = 6
13 - 2 = 11
11 - 2 = 9
13 - 8 = 5
11 - 8 = 3
13 - 11 = 2
(6+11+9+5+3+2)/6 = 36/6 = 6

Excel find last record of specified value in range

I have a excel formula question.
I have table/range of some accounts activity during days with amounts as bellow
date / account / amount
1-Jan / 20 / 60
1-Jan / 30 / 2
2-Jan / 20 / 3
2-Jan / 20 / 4
3-Jan / 10 / 5
4-Jan / 20 / 6
I want to extract last record of given accounts as bellow
10 -> 3-jan / 5
30 -> 1-Jan / 2
which formulas will find last in range based on criteria?
How Can do it?
In Excel 2016 from a 365 license, you can use the new MAXIF. In previous versions, use an array formula like this in F2 in the screenshot:
=MAX(IF($B$2:$B$7=E2,$A$2:$A$7))
Note that it must be confirmed with Ctrl-Shift-Enter, otherwise it will not work.
Then look up the amount with this formula in G2 in the screenshot.
=INDEX($C$2:$C$7,MATCH(F2&E2,INDEX($A$2:$A$7&$B$2:$B$7,0),))
Copy both formulas down

Nested array formulas

I want a summation of rates. Let me explain it: I would like to sum the numbers in column D that matches 2 conditions (green rows in excel). First one: column F equal to "closed". Second one: column C equal to those numbers which in turn matches the following condition: column F equal to "Partial Sold". At the same time, EACH number in the previous summation might be divided by the number of column D which matches "Partial Sold" in column F.
There is the example with the table/figure I attached: (4510 / 9820) + (6500 / 9820) + (9100 / 15400) + (2388 / 2995) + (12400 / 9820) + (2904 / 5855).
My cells would be: (D69 / D66) + (D70 / D66) + (D76 / D74) + (D82 / D78) + (D83 / D66) + (D84 / D72).
#Jeeped with your cells would be: (D6 / D3) + (D7 / D3) + (D13 / D11) + (D19 / D15) + (D20 / D3) + (D21 / D9)
.. C D E F
65 # Total Side Condition
66 1 9820 Buy Partial Sold
67 2 3850 Buy Closed
68 3 7151 Buy Partial Sold
69 1 4510 Sell Closed
70 1 6500 Sell Closed
71 4 8180 Buy Open
72 5 5855 Buy Partial Sold
73 6 2553 Buy Open
74 7 15400 Buy Partial Sold
75 2 4600 Sell Closed
76 7 9100 Sell Closed
77 8 7531 Buy Open
78 9 2995 Buy Partial Sold
79 3 3000 Sell Closed
80 10 8691 Buy Open
81 3 2500 Sell Closed
82 9 2388 Sell Closed
83 1 12400 Sell Closed
84 5 2904 Sell Closed
85 11 3848 Buy Open
86 12 7745 Buy Open
To do it in one step with an array formula you could use:
=SUM(IFERROR((D66:D86*(F66:F86="Closed"))/((C66:C86=TRANSPOSE(C66:C86))*TRANSPOSE(D66:D86*(F66:F86="Partial Sold"))),0))
This is an array formula and must be confirmed with Ctrl+Shift+Enter↵.
it will generate a 2D-array holding the original values for closed as rows and divides this 1D array by this:
buils up 2D-array by col C = transposed col C
multiply each row by col D
set all items in each row to 0 if not "Partial Sold"
for each div by 0 the IFERROR will set it to 0
and this all in the SUM will give you your output
I too would recommend using a helper column. You don't need to use array formulas to get to the answer though. You can use the following in the next available column:
=IF(F66="Closed",IFERROR(D66/SUMIFS($D$66:$D$86,$F$66:$F$86,"Partial Sold",$C$66:$C$86,C66),0),0)
This will return values for everything that matches your criteria, and zeroes for everything else. Then you can just take the sum of this helper column as your final summation of rates.
If you really don't want to use a helper column, you can wrap the helper column formula in a SUM and swap out the individual cell references for arrays (i.e. swap F66 for $F$66:$F$86, and so on), then enter it as an array formula with Ctrl+Shift+Enter↵. The whole thing would look like this:
=SUM(IF($F$66:$F$86="Closed",IFERROR($D$66:$D$86/SUMIFS($D$66:$D$86,$F$66:$F$86,"Partial Sold",$C$66:$C$86,$C$66:$C$86),0),0))
I do not see this being done without a helper column. In an unused column to the right of F66, put this array¹ formula.
=IF(AND(OR(C66=INDEX(C$66:C$86*(F$66:F$86="Partial Sold"), , )), F66="Closed"), D66/INDEX(D$66:D$86, AGGREGATE(15, 6, ROW($1:$21)/((C$66:C$86=C66)*(F$66:F$86="Partial Sold")), 1)), "")
Fill down as necessary. The result will be the sum of those 'helper' numbers.
        
Even if this could be done in a single formula, the calculation overhead would likely be prohibitive. Splitting a portion of the array calculations off to a helper column that can directly reference the value in column C for another lookup reduces this significantly.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.

Resources