I have a database of about 100 columns with similar data to from COL A to COL H.
I use the formula in COL J to search in a column for two consecutive rows with "-" and mark the second row as a double as you can see on J16 and J32. This method is time consuming because I do often search for different columns and have to change the formula each time.
I would like something like N3. Entering the column ID and when I hit enter I will get automatically the count of rows with two consecutive "-" and also I would like to increase to search for triples and quadruples.
Any help will be appreciate.
Formula on J2:
=IF(AND(OR(F2=F1,F1="-"),F2="-"),"double","")
In N5 to count doubles,
This is the dynamic equivalent of using,
In N6 to count triples,
In N7 to count quads,
If you require quints, you should be able to get the idea from those.
You want to use your column entry in cell N3. You can do this using the indirect function. Just change the formula in cell J2 from this:
...to this:
You can catch triples and quadruples in the same way, try this formula ...it'll only work from row 4 onwards, and the results may feel messy, depending on what you need:
With reference to the figure at the bottom, there are:
Helper cells
N1:N2
andN9:N19
, whose contents helps the formulas you need being more concise. See below the explanation and formulas for these.Cells with the formulas you need, using
SUMPRODUCT
combined with some form of dynamic referencing.Cells
N5:N7
give the result you want, but with fixed references. These areN5
:=SUMPRODUCT(($G$2:$G$21="-")*($G$3:$G$22="-"))
N6
:=SUMPRODUCT(($G$2:$G$20="-")*($G$3:$G$21="-")*($G$4:$G$22="-"))
N7
:=SUMPRODUCT(($G$2:$G$19="-")*($G$3:$G$20="-")*($G$4:$G$21="-")*($G$5:$G$22="-"))
You can grasp the systematics.
Cells
O5:O7
give the same result, usingINDIRECT
instead of fixed references (option #1 for what you need, see this). These areO5
:=SUMPRODUCT( (INDIRECT($N$3&$N$9):INDIRECT($N$3&($N$10-1))="-") *(INDIRECT($N$3&($N$9+1)):INDIRECT($N$3&$N$10)="-") )
O6
:=SUMPRODUCT( (INDIRECT($N$3&$N$9):INDIRECT($N$3&($N$10-2))="-") *(INDIRECT($N$3&($N$9+1)):INDIRECT($N$3&($N$10-1))="-") *(INDIRECT($N$3&($N$9+2)):INDIRECT($N$3&$N$10)="-") )
You can grasp the systematics and write the formula for cell
O7
.Cells
P5:P7
give the same result, usingOFFSET
instead of fixed references (option #2 for what you need, see this, this, or this). These areP5
:=SUMPRODUCT( (OFFSET($A$1,$N$12,$N$14):OFFSET($A$1,$N$13-1,$N$14)="-") *(OFFSET($A$1,$N$12+1,$N$14):OFFSET($A$1,$N$13,$N$14)="-") )
P6
:=SUMPRODUCT( (OFFSET($A$1,$N$12,$N$14):OFFSET($A$1,$N$13-2,$N$14)="-") *(OFFSET($A$1,$N$12+1,$N$14):OFFSET($A$1,$N$13-1,$N$14)="-") *(OFFSET($A$1,$N$12+2,$N$14):OFFSET($A$1,$N$13,$N$14)="-") )
You can grasp the systematics and write the formula for cell
P7
.There are likely other options combining
INDIRECT
andOFFSET
(see this). An option usingINDEX
(although likely not the only variant) was covered by Jeeped.Note on helper cells: I suggest having helper cells, and this applies to other answers posted here as well. Of course you may move these cells around, adjusting the corresponding formulas. The only non trivial formula here is for cell
N11
,=COLUMN(INDIRECT($N$3&"1"))
(see this or this). CellN19
may be useful if you are going to useINDEX
.