Count until first three consecutive blank columns - excel

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.

Related

finding next empty row

This might be easy for many but I need to solve an issue which is following;
I have the following formula which finds the empty row after D4.
=MATCH(TRUE;D4:D1048576="";0)+3
After this I want to be able to find the empty row from another defined cell, say D10.
How can I do this?
Try this as an array formula - Ctrl+Shift+Enter:
=MIN(IF(D4:D100="",ROW(D4:D100)))
It works from D4 to D100, providing the first empty value.
If you're looking to use same formula to match next cell then use
For blanks after D4
=MATCH(TRUE,INDEX(ISBLANK(D4:D1048576),0),0)
For blanks after D10
=MATCH(TRUE,INDEX(ISBLANK(D10:D1048576),0),0)
To find the A1th blank cell, you can use the following formula:
=AGGREGATE(15,6,ROW(D:D)/--ISBLANK(D:D),A1)
How it works
AGGREGATE(15,6,..) is like SMALL(..), but skips any error values.
ROW(..) provides the row number of the cell provided
ISBLANK(..) is TRUE for blank cells or FALSE for non-blank cells
-- converts TRUE to 1 and FALSE to 0. This means that ROW(D:D)/--ISBLANK(D:D) will be either the Row Number (for blank cells) or a #Div0! error (which AGGREGATE will skip)
This produces a list of row numbers for all the blank cells, and you then use the AGGREGATE function to get the kth item in that list.
Taking it a step further
So, you want the 1st item larger than a specific row. We change the last argument in AGGREGATE to 1, and swap change our "Error out" code from ISBLANK(D:D) to AND(ISBLANK(D:D), ROW(D:D)>A1), to get the first blank row after the row number stored in A1:
=AGGREGATE(15, 6, ROW(D:D)/--AND(ISBLANK(D:D), ROW(D:D)>A1), 1)

How to give reference to a row number in excel formula?

I need this formula: C(n) = B(n)*A5. (n is the row number)
Literally, multiply the current selected row number in column B with A5
I tried =ROW function for creating a reference but failed.
I tried with this formula: C(2) =MULTIPLY(B=ROW(),A5) thinking it will be parsed to C(2) =MULTIPLY(B2,A5)
You have two options to accomplish this:
1. INDEX() formula:
=INDEX(B:B,ROW())*A5
2. INDIRECT() formula:
=INDIRECT("B"&ROW())*A5
Where ROW() is the number of cell you're entering this formula into.
Found it.
=MULTIPLY(INDIRECT("F" & ROW()),INDIRECT(("G" & 2)))
INDIRECT(("G" & 2)) even makes it better if you want to drag and copy the functionality to all the rows below.

Sum cells values with a separation of 3 columns in Excel

I would like to create a formula that sums all the values that I'm going to add in the future in some cells of the same row. For example, I would like to add cells D3,G3,J3,M3 and so on (separated 3 rows) in cell D1.
Best regards,
A good solution will depend on what (if anything) is in the intervening columns on row 3. A SUMPRODUCT function can produce some nice results by checking the stagger or offset of the columns but it isn't going to like text put into the intervening cells.
=SUMPRODUCT((INDEX(3:3, 1, 4):INDEX(3:3, 1, MATCH(1E+99,3:3 )))*NOT(MOD(COLUMN(INDEX(3:3, 1, 4):INDEX(3:3, 1, MATCH(1E+99,3:3 )))-1, 3)))
By switching to an array formula and a condition SUM function, you should be able to happily skip over any text values.
=SUM(IF(NOT(MOD(COLUMN(INDEX(3:3,1,4):INDEX(3:3,1,MATCH(E1+99,3:3)))-1,3)),INDEX(3:3,1,4):INDEX(3:3,1,MATCH(E1+99,3:3))))
Array formulas need to be finalized with Ctrl+Shift+Enter↵.
If neither ot those fits the bill, provide a little more information on the nature of what not to sum and more help can be offered.
This will do the job:
1) put =SUM(D2:XFD2) in cell D1
2) put =IF(MOD(COLUMN(D3)+2,3)=0,IF(D3="","",D3),"") in all cells from (D2 .. til the end)
3) put your data in D3 .... til the end.
Anonymous' solution works if you only need to sum one row. If you need to be able to drag that formula down, consider using a flag in row 2 to identify every 3rd column (like Anonymous did) , and use a sumif formula to add the columns where that flag is present.
Type
=
in the cell where your first result will appear (e.g. D1).
Click on the first value in the first row.
Press + on numpad.
Click on the next value in the next row.
Repeat steps 4-5 until you reach the last row.
Press Enter.
You can now select the results-cell (e.g. D1) and click and drag the small button to your lower right, across all the columns.
If you have a static reference - a constant in a cell that you do not wish to move use the $ operator, for example: $C$3 will not move column-wise or row-wise. $C3 can move column-wise but not row-wise and the opposite is true for C$3. This can be achieved in the Formula Bar, where you can also manually type in the function.

Find blank count in a row with most blanks within a 2D array of cells

I want a formula that will look in a 2D array of cells for the row that has the most blank cells in it. Then I want the number of that row's blank cells returned as shown in the picture. The "Title 2" row has the most blanks at 4 as displayed in B8. I would want the formula to take the whole table into considerations, so cells B2:G5
Or this array formula**:
=MAX(MMULT(0+(LEN(B2:G5)=0),TRANSPOSE(COLUMN(B2:G5)^0)))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
Sometimes it's easier to break things up into two tasks:
A formula in Column H that counts blanks by row. Something like: =COUNTIF(B2:G2, "="&"") which you would drag down through row #5.
Then, just make Cell B8 the maximum of that new column: =MAX(H2:H5).
I'd be curious if there is some type of array formula trick to accomplish this is one formula. Nevertheless, personally, I find separating the logic into smaller, more manageable, formulas easier to maintain.
In H2 enter:
=COUNTBLANK(B2:G2)
and copy down. In B8 enter:
=MAX(H2:H5)
For example:
Several great answers already, but I'll throw this out there:
=MAX(COUNTBLANK(INDIRECT("B"&ROW(2:5)&":"&"G"&ROW(2:5))))
Enter as an array formula: Ctrl+Shift+Enter
This:
"B"&ROW(2:5)&":"&"G"&ROW(2:5)
… returns an array of strings {"B2:G2" , "B3:G3" , "B4:G4" , "B5:G5"}:
That array is fed to the INDIRECT function, which changes it into an array of ranges {B2:G2 , B3:G3 , B4:G4 , B5:G5}.
That new array is fed to the COUNTBLANK function, which (using your example) returns the array of numbers {2 , 4 , 1 , 3}.
That's fed to the MAX function, so the end result is the number 4.
It's a bit convoluted, so I'm wondering if my INDIRECT parameter can be simplified.

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