How to repeat a value each x cells? - excel

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:

Related

How to count until a certain value?

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)

A function or VBA code to determine the last digit in a number

In Excel 2016 I have multiple rows containing numbers no greater than 3 characters listed in column A. I am trying assign a group number based on the right most character in each row that are in column A. Once the number is determined the result is placed in column B of the corresponding row.
Example:
If rightmost character of the number is: a 1 or 6 in cell A1, then in column B1 it's given a 1.
If A1 is a 2 or 7 then B1 is 2.
If A1 is a 3 or 8 then B1 is 3.
If A1 is a 4 or 9 then B1 is 4.
If A1 is a 0 or 5 then B1 is 5.
Any suggestions on how to perform with a function or VBA code are appreciated.
Following your problem statment exactly: in B1 you can enter the formula:
=IF(MOD(MOD(A1,10),5)=0,5,MOD(MOD(A1,10),5))
And copy it down as needed.
The part MOD(A1,10) pulls off the last digit. You seem to want the remainder of this mod 5 -- hence the outer MOD in (MOD(MOD(A1,10),5). But -- if the mod is 0 you want to report it as 5 -- hence the overall IF
However -- an even quicker way is just:
=IF(MOD(A1,5)=0,5,MOD(A1,5))
Since literally pulling off the first digit is superfluous since 5 is a divisor of 10.
Finally, #chrisneilsen gave an elegant formula which is even shorter:
=MOD(A1-1,5)+1
For all remainders other than 0 , the -1 inside the MOD and the +1 outside cancel each other, but for multiples of 5 (remainder 0) the -1 inside the MOD converts the number to one with a remainder of 4, with 4 + 1 = 5 the final answer.

Way to count last values before each zero?

I am trying to count the last value before it resets back to zero multiple times per column. Here is my example
1
2
3
4
5
6
7
8
0
1
2
3
4
5
6
0
1
0
0
1
2
3
0
And the list goes on but for this example I would be looking to do something like a LARGE or SMALL where I could get the answers like this:
8
6
1
3
Ultimately I would like them to be in the descending order, but if that isn't part of the formula I can take care of that if I can just figure out a way to capture them.
Can this be done?
You can try the following in column B try the following =IF(A2=0,IF(A1=0,"";A1),"")
then filter column B on non blank value
Put your original data in column B
In cell A2 enter:
=IF(AND(B2<>0, B3=0),MAX($A$1:A1)+1,"")
and copy down. Finally in C1 enter:
=VLOOKUP(ROW(),$A$1:$B$23,2,FALSE)
and copy down till you see errors. Should look like:
Basically column A is a "helper" column used to mark all the "good" values to facilitate easy pick-up

How to count number of matches between two columns in Excel?

How to count number of matches between two columns in Excel?
For example if we have:
1 1
2 1
3 2
4 4
5 3
I need to get either a column like this:
1
0
0
1
0
and then I can sum the ones in there to get the count of matches.
Option 1: IF
=IF(A1=B1;1;0)
This formula will put 1 in the cell if A1 = B1, and 0 otherwise.
Option 2: COUNTIF
Write =A1=B1 in C1, etc., in the column cells. This will fill the C column with TRUE and FALSE values.
At the bottom of that column, add a cell =COUNTIF(C1:C100;TRUE) so that you count the cells between C1 and C100 which have value TRUE.
You may find the TechRepublic article Use COUNTIFS() to compare two data sets in Excel of use. See also Microsoft's documentation on countifs().

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