Count no of values from last till blank cell - excel-formula

sample example for my request
Here I use this following formula -> =MAX(IF(LEN(C2:AF2)<>0,COLUMN(C2:AF2))) - MAX(IF(LEN(C2:AF2)=0,COLUMN(C2:AF2)))
and -> =COLUMNS(C6:L6)-MATCH(9.99999999999999E+307,C6:L6) give you no of blank cells from right side.

Try this in AF2 and fill down.
=MATCH(1E+99, C2:AF2)-AGGREGATE(14, 7, COLUMN(2:2)/(C2:INDEX(2:2, 1, MATCH(1E+99, C2:AF2))=""), 1)

Related

Excel vlookup get the highest value

Here is the excel function:
start date =IF(A6 = 1, C3, VLOOKUP(A6 -1, $A$6:$D$13, 4, FALSE))
end date =C6+B6
I intend to get the latest end date value if there is multiple rows on previous sequences, for example as below:
On the yellow cell, it should get the 23/2/2019 instead of 18/2/2019.
Use LOOKUP:
=IF(A12=1,C9,LOOKUP(A12-1,$A$6:$A$13,$D$6:$D$13))
Edit:
to get latest date you can use AGGREGATE function:
=IF(A6 = 1; C3; AGGREGATE(14;4;($A$6:$A$13=A6 -1)*$D$6:$D$13;1))
I think this will serve your purpose. This is formula for first start-date value and drag it downwards.
=IF(A6=1,$C$3,MAX(IF(A6-1=$A$6:$A$14,VLOOKUP(A6-1,$A$6:$D$14,3)+$B$6:$B$14)))
NOTE this is array formula so enter it with ctrl + shift + enter and check for curly braces around the formula. The screenshot to check for all conditions
Check for seq 6, I added two values sorted differently now

Excel : How to apply a criterion to each cell in an array?

So in the example above, I would like to extract all cells that contain "A" as the first letter(and length=9, though it does not matter). Now I am able to run the function for one cell, but I want to run it as an array formula so that I do not have to drag down 1000 cells every time. Below is my code:
=IFERROR(INDEX($A$1:$A$3, IF(AND(LEFT(A2,1)="A", LEN(A2)=9), ROW($A$1:$A$3),"")),"")
The problem here is that when I enter the code with "Ctrl + Shift + Enter", the criteria would be only confined to A2, which is the cell address I manually entered. Is there anyway to check for every single cell without having to drag down WITHOUT USING VBA? I know using VBA would make it a lot easier, but I just want to understand the basics of Excel further.
Try,
=iferror(index(a:a, aggregate(15, 7, row(a:a)/(left(a$1:index(a:a, match("zzz", a:a)))="a"), row(1:1))), text(,))
'with 9 length criteria
=iferror(index(a:a, aggregate(15, 7, row(a:a)/((left(a$1:index(a:a, match("zzz", a:a)))="a")*(len(a$1:index(a:a, match("zzz", a:a)))=9)), row(1:1))), text(,))
Fill down as necessary.
If you only want the single left-most character from a string of text, you do not have to supply a 1; you can omit the number of characters argument.

Formula to find the second to last value in row - Excel

I have the formula to find the last value in a row - =LOOKUP(1,1/(3:3>0),3:3) (depending on the row)
but can't seem to get it to return the second to last value/cell in the row.
Please help!
Try,
=INDEX(3:3, AGGREGATE(14, 6, COLUMN(A:XFC)/(A3:XFC3>0), 2))
Awesome.. I edited the formula to:
=INDEX(3:3, AGGREGATE(14, 6, COLUMN(A3:XFC3)/(A3:BL3>0), 2))
Where BL3 is where my current last data value ends. Once I drag, the formula automatically updated the column and row value.
Thanks so much!
For row #3, the array formula:
=INDEX(3:3,IF(COUNTA(3:3)=0,"",MAX((3:3<>"")*(COLUMN(3:3))))-1)
will yield the next-to-last value in that row:
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.
If you are sure that row #3 will not be empty, then use this array formula instead:
=INDEX(3:3,MAX((3:3<>"")*(COLUMN(3:3)))-1)
To avoid array formulas consider:
=INDEX(3:3,SUMPRODUCT(MAX((COLUMN(3:3))*(3:3<>"")))-1)

Count until first three consecutive blank columns

I am having trouble mixing the counting cells with value '1' until the first three consecutive blank cells. The following image as the example:
Is it possible to do it only with Excel formulas or do I have to use other code?
Your problem is not so much identifying the three terminating blank cells as trailing the last three blank cells off to 2 cells then 1 cell at the end of the B:Z range. If you can extend the range to guaranteed blank cells in AA:AC then you can use an array formula¹ to accomplish the 'three-blank-cell-match' with a progressively staggered range.
    
The array formula¹ in A2 is,
=COUNTIF(B2:INDEX(B2:AA2, MATCH(1E+99, IF(B2:AA2="", IF(C2:AB2="", IF(D2:AC2="", 1E+99))), 0)), 1)
Fill down as necessary.
counting cells with value '1' until the first three consecutive ...
The formula may be more universal if counting ones is the primary task. Simply switch the conditions to any three consecutive cells that are not i.
    
The array formula¹ in A2 is,
=COUNTIF(B2:INDEX(B2:AA2, MATCH(1E+99, IF(B2:AA2<>1, IF(C2:AB2<>1, IF(D2:AC2<>1, 1E+99))), 0)), 1)
Fill down as necessary. Note that I've modified the last row to show more matches.
¹ 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.
I think most worksheet functions are going to get pretty messy for this type of task, however, one way you could go about it is something like this...
=COUNT(INDIRECT("R[0]C[1]:R[0]C[" & FIND("0",CONCATENATE(SUM(B1:D1),SUM(C1:E1), SUM(D1:F1), SUM(E1:G1), SUM(F1:H1), SUM(G1:I1), SUM(H1:J1), SUM(I1:K1), SUM(J1:L1), SUM(K1:M1), SUM(L1:N1), SUM(M1:O1), SUM(N1:P1), SUM(O1:Q1), SUM(P1:R1), SUM(Q1:S1), SUM(R1:T1), SUM(S1:U1), SUM(T1:V1), SUM(U1:W1), SUM(V1:X1), SUM(W1:Y1), SUM(X1:Z1), SUM(Y1:AA1), SUM(Z1:AB1))) & "]",FALSE))
This works for columns A to Z, of course, it ends up being very long. Alternatively, more options are on the table if you enable iterative calculations, then you can use something like this.
In A1: =COUNT(INDIRECT("R[0]C[3]:R[0]C[" & B1 & "]", FALSE))
In B1: IF(C1 > 0,B1+ 1,B1)
In C1: =COUNT(INDIRECT("R[0]C[" & B1 - 2 & "]:R[0]C[" & B1 & "]",FALSE))
The problem with this is it requires iterative calculations and is only valid if it begins its iteration with range B1 having a starting value of 0. One way you could streamline an iteration reset would be with a switch like this...
In B1: =IF(B2="",IF(C1 > 0,B1+ 1,B1),0)
A VBA function is likely your best bet if you can pull it off. You could build something like this...
Function CountBeforeBlanks(R As Range)
For i = 1 To R.Count
CountBeforeBlanks = CountBeforeBlanks + R(i)
If Application.WorksheetFunction.Count(R(i), R(i + 1), R(i + 2)) = 0 Then
Exit Function
End If
Next
End Function
Enter this formula in cell A2 and then copy downward as far as needed:
=COUNTA(OFFSET(B2,,,,-1+FIND("111",--(B2="")&--(C2="")&--(D2="")&--(E2="")&--(F2="")&--(G2="")&--(H2="")&--(I2="")&--(J2="")&--(K2="")&--(L2="")&--(M2="")&--(N2="")&--(O2="")&--(P2="")&--(Q2="")&--(R2="")&--(S2="")&--(T2="")&--(U2="")&--(V2="")&--(W2="")&--(X2="")&--(Y2="")&--(Z2=""))))
.
UPDATE
Here is a shorter version that works the same way. No extra columns required:
=COUNTA(OFFSET(B2,,,,-1+FIND("000",
RIGHT(DEC2BIN(SUM(256,(LEN(B2:I2)>0)*2^{7,6,5,4,3,2,1,0})),8)&
RIGHT(DEC2BIN(SUM(256,(LEN(J2:Q2)>0)*2^{7,6,5,4,3,2,1,0})),8)&
RIGHT(DEC2BIN(SUM(256,(LEN(R2:Y2)>0)*2^{7,6,5,4,3,2,1,0})),8)&--(Z2<>"")
)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.

Cell Referencing Formula

Was using this formula SheetName!CellAddress
I need to import Data that is available on other 2 sheets namely (sheet2 and sheet3) into sheet 1 in a way such that
the row values will be alternate i.e one value from sheet 2 and other value from sheet 3 respectively
Have tried like this
=Sheet2!C2
=Sheet3!D2
when i dragged for other values i was get only values in the even cell like(c4,d4,c6,d6)
If i change the for formula to
=Sheet2!C1
=Sheet3!D1
i was get only values in the even cell like(c3,d3,c5,d5)
But what i need is continous cells in row( c1,d1,c2,d2,c3,d3...)
So what formula i need to use for getting this result
I am still not 100% clear on what the question is asking, so let me know if the below answer doesn't work for you.
It sounds like what you're looking for can be accomplished with OFFSET and clever use of IF statement.
Suppose your formulas will be in column A, starting in A2. Then enter the following formula into A2 (line split added for readability; remove it):
= IF(MOD(COUNTA(A$1:A1),2)=0, OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0),
OFFSET(Sheet3!$D$1, COUNTA(A$1:A1) / 2, 0))
Then drag the formula down.
What it does:
MOD(COUNTA(A$1:A1),2)=0 - checks whether we're in odd row or even row.
COUNTA(A$1:A1)/ 2 - takes half of the number of non-empty cells immediately above the current cell.
OFFSET(Sheet2!$C$1, COUNTA(A$1:A1) / 2, 0) - takes the cell which is COUNTA(A$1:A1)/ 2 cells below Sheet2!$C$1.
Here's a fairly basic method:
Enter the first two formulas as Text - you can either do this by formatting the cell number as text or preceding the formula by an apostrophe.
Select cells and fill down to get:
=Sheet2!C2
=Sheet3!D2
=Sheet2!C3
=Sheet3!D3
=Sheet2!C4
=Sheet3!D4
...
Select the column and choose Data|Text to Columns|Finish to change text to values.

Resources