How to count until a certain value? - excel

I am just using formulas in excel and was wondering how you could count all the 0s until a 1 is reached, and then start the process over again. Would this be possible with just formulas?
Right now I am trying to use,
=COUNTIF(INDIRECT(F2:F28,0)),1)
... but it does not seem to work.
Data:
0
1
0
1
1
0
0
0
0
0
0
1
0
1
0

What you're describing here is known as a (Do) While loop in VBA.
Admittedly, something VBA is much better equipped to handle than a formula - literally needs few lines of code. Should be something you should consider looking into
You can technically fake a Do While with a formula. But this is
generally a practice I would not exactly recommend.
Under presumption you data input starts in Cell F2 then formula in adjacent Column G2
=IF(F2=0, SUM(G1, 1), 0) and drag the formula accross. Produces the expected result

In B2 enter:
=IF(OR(A2=0,A1=1),"",COUNTIF($A$1:A1,0)-SUM($B$1:B1))
and copy downward:

This seems to work according to your sample data,
=COUNTIF(F2:INDEX(F:F, IFERROR(AGGREGATE(14, 7, ROW($1:2)/(F$1:F2=1), 1), ROW(F2))), 0)

I have a solution, but it's not very elegant. Maybe someone else can improve on it. But here it is:
Assuming your data is in column A.
1) In B1 enter a 1 if A1 is a 0 or 0 if A1 is a 1.
2) In B2 enter the formula =IF(A2=0,B1+1,0)
3) Drag the above formula all the way down
4) In C1 enter the formula =IF(B1>B2,B1,"")
5) Drag the above formula all the way down
6) Column C should now have all of the counts of zeroes.

You can use the following formula in column B:
=IF(A3=1,COUNTIF(A$1:A2,0)-SUM(B$1:B1),"")
starting in row 2 and drag it down.

Put 1 in the cell next to the first 0 (In my example that's in A1, so i've put 1 in B1);
Then try this =IF(A2=A1;B1+1;1)

Related

Conditional Formula for excel

I am trying to do addition/subtraction from a total of one column, based on the value of a different column.
Here are the details:
Column H2:H61 has 3 possible values: Complete, Incomplete, Does Not exist.
Column I2:I61 are integers.
What I'm trying to accomplish is, for each Row in column H, evaluate if the value is "Complete". If it is, then, in a running total cell, convert the corresponding Row in I to a negative number and add it to the total. If it isn't, leave the number a positive number and add it to the total.
Example:
H2 = "Complete" I2 = 1.5
h3 = "Incomplete" I3 = 0.5
h4 = "Complete" I4 = 2.0
The total is 3
EDIT
Here is the full scope of it:
Excel Screenshot
So, the total values of I and L is currently 40.
What I'm trying to do is, for example, if H2 = "Complete", then I want to subtract I2 (which is 1.5), which would change the total value to 38.5.
H3 is "Does Not Exist" and != "Complete", so the total would still be 38.5.
H4 is "Complete", so the total would be 37.5
so on and so forth. Hope this helps clarify for everyone!
Try following formula in K2 cell then drag and down.
=SUMIF($H$2:$H2,"Complete",$I$2:$I2)-SUMIF($H$2:$H2,"Incomplete",$I$2:$I2)
I guess you want something like:
=40-SUMIF(H:H,"Completed",I:I)
assuming you do not have the 40 total in either Column H or I.
I figured it out.
What I did was in a separate cell I made the following formula:
=SUMIF(H2:H61,"Completed",I2:I61)
From there, I used that cell to create the following formula to get the result I wanted:
=P31 - (S30+S31)
The S30 and S31 cells are there because I was counting for each "completed" value in two separate columns.

Excel sum one column based on another

I have data that is divided into columns as follows:
Runs RunsAfter Switch New
0 2 1
0 2 0
1 2 0
0 1 0
1 1 0
0 0 0
0 0 0
0 0 1
0 1 0
1 1 0
0 0 0
I want excel to sum the Runs column by taking each cell and summing down the remainder of the column until there is a 1 in the Switch column. It should then start calculating again until another Switch. All of this output should be put in the New column. The result should look like the RunsAfter column, which I am currently calculating by hand. I would keep doing this, but the dataset is going to get too big to continue doing this by hand.
I've checked for questions similar to this, but haven't been able to find quite what I'm looking for. If I've missed an answer elsewhere, please let me know.
If I am understanding correctly, I think you want to use a combination of the match formula to find the next "switch" and the indirect formula to define the range to sum. I can't think of a simple way to do this.
This is assuming that your headers are in row 1 and your columns are Runs (A), RunsAfter (B), Switch (C), and results in D. I've used 100 for your last row, but you will need to change that if you have more rows. This is what I did in D2:
To find the next row for which Switch is 1:
MATCH(1,C3:$C$100,0)+ROW()
I also included iferror to make it not break for rows after the last switch:
IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)
I included this as part of the indirect formula to tell it what range to sum up:
D2=SUM( INDIRECT("A"&ROW()&":A$"&IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)))
So for D2, it's summing from A2 to the row before the next switch, in this case row 8. You should be able to drag it down from D2 with those anchors.

How to repeat a value each x cells?

The idea is to have 2 inputs the number and the number of spaces, so lets say those numbers are 2 & 3 it should look like:
2
0
0
0
2
0
0
0
2
If first parameter is in A1, second in B1, you can enter the following formula in any cell, and fill it down:
=IF(MOD(ROW(A1),$B$1+1)=1,$A$1,0)
Your sample data is confusing in that there are three 2's and three zeroes. It's unclear on what it should look like if the second number was a 4. If it is always three of the first number try something using REPT. With 2 in A1 and 3 in A2,
=A1&rept("0", A2)&A1&rept("0", A2)&A1
Pick a cell and enter:
=IF(MOD(ROWS($1:1),4)=1,2,0)
and then copy down:

Highlight duplicate numbers if it occurs more than once in excel

Can someone please give a detailed explanation of how to do this.
I'm given a data set containing over 8000+ numbers. They are either 0 or 1 listed in the first column, 'A.' I'd like to know a formula for how to highlight any 0's if they occur 6 or more times consecutively.
I've used =Countif($A$1:A1,A1)>3 as an example, but it doesn't work. Just highlights some of the 0's. Example of what I'd like.
A1: 0
A2: 0
A3: 1
A4: 0
A5: 1
A6: 0
A7: 0
A8: 0
Any help would be appreciated.
Select from cell A6 down to the end of the column. Create a conditional format with this formu.a:
=OR(SUM(A1:A6)=0,SUM(A2:A7)=0,SUM(A3:A8)=0,SUM(A4:A9)=0,SUM(A5:A10)=0,SUM(A6:A11)=0)

Microsoft Excel 2010: Help making a Formula to up Values by a repeating pattern

I have a Spreadsheet, and inside this sheet contains a column with numbers, I want to make a formula that will go down that Column and do basically this.. Values: 1 will be 9.50. 2 will be 9.75. 3 will be 10.00. Ect going up to Value of 100? Is that possible for a Formula? I keep playing with it but can't really seem to get it down. Any help would be appreciated.
Column A: 1
1
1
1
1
2
2
2
2
2
2
2
2
2
3
3
3
3
There is not a set amount to how many values are in there.
this should do it supposing that column A has these values 1, 2 ...etc that your computing will be based on
=MIN(9.25+A1*0.25;100)*COUNT(A1)
In A2, enter the formula
=A1 + (9.5-A1)
then in the cell just below it (A3), enter
=A2+0.25
Assuming A1 is the top left. Copy the formula in A3, select the next 399 cells and paste. Then select A2 - A364 and copy. Then select B2 -xx364 and paste. xx is the last column with data. If you want, set the height of your first column to 0 to hide it.
=(A1-1)*0.25+9.5 where A1 contains any number you want

Resources