Incrementing multiple sequence of numbers in single excel column - excel

I wanted to run multiple sequences of numbers in a single column in excel sheet. For example, this is how a sample output should look like :
As you can see, there are two separate sequences of numbers that are running in single column. One starts from "1" and another starts from "100". What formula can I write in excel such that excel leaves a gap of two rows after "1" and "2" and continues to "3" and "4" and so on.
In this example, I have shown two sequences of numbers which are running in a single column, how can I extend that for 3 or 4 sequences etc.

Here is a draft of how it might look. Basically taking the row number and looking up the corresponding start value, but subtracting out the terms belonging to the other series (two in this case) and subtracting out the rows before it in the current iteration of the series:
=INDEX(A$2:A$4,MATCH(MOD(ROW()-2,9),C$2:C$4))+ROW()-2
-QUOTIENT(ROW()-2,9)*SUMPRODUCT(B$2:B$4*((ROW(B$2:B$4)-1)<>MATCH(MOD(ROW()-2,9),C$2:C$4)))
-INDEX(C$2:C$4,MATCH(MOD(ROW()-2,9),C$2:C$4))
Can be developed into a spill formula in O365 and tidied up removing the helper column and the hard-coded '9' and using Sequence and Let.
So the whole thing in O365 would be
=LET(startRange,A2:A4,
countRange,B2:B4,
cumTotal,MMULT(IF(ROW(countRange)>TRANSPOSE(ROW(countRange)),1,0),countRange),
rowSeq,SEQUENCE(100,1,0),
totCount,SUM(countRange),
modRow,MOD(rowSeq,totCount),
series,MATCH(modRow,cumTotal),
startValue,INDEX(startRange,series),
countForSeries,INDEX(countRange,series),
quotient,QUOTIENT(rowSeq,totCount),
subtract1,quotient*(totCount-countForSeries),
subtract2,INDEX(cumTotal,series),
startValue+rowSeq-subtract1-subtract2)

Related

Excel - Add an excel formula within FilterXML

I have an excel spreadsheet containing a list of strings in one column. The list of strings is made up of several numbers from varying lengths, separated by “/” and “;” The first entry of the string is a code id (which always has a length of 3)(red in example) followed by an “/” then an amount (which varies in length)(green in example) followed by an “;” if the string continues.
With the help of a member, I can now isolate the green number with the following formula:
=IF(ISBLANK(A4);"";TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A4;"/";";");";";"</s><s>")&"</s></t>";"//s[position() mod 2 = 0]")))
However, I still need an other formula that multiplies the green number with a variable, if a condintion is met.
Example function:
=IFS(B2<=10;B2*1,25;B2<=20;B2*1,18;B2<=100;B2*1,05;B2<=250;B2*1,01;B2>250;B2)
Is there a way to combine both these functions?
A very nice way of dealing with this is assigning the full array to a name, let's say a variable, through LET(). So your formula in B2 would become:
=IF(A2<>"",LET(MNT,TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A2,"/",";"),";","</s><s>")&"</s></t>","//s[position() mod 2 = 0]")),IFS(MNT<=10,MNT*1.25,MNT<=20,MNT*1.18,MNT<=100,MNT*1.05,MNT<=250,MNT*1.01,MNT>250,MNT)),"")
It, however, does require Excel O365. But since you are transposing the array it appears you do have that.

How to count number of cells whose contents start with 0?

I need to count how many cells are in a column, but all the content of the cells are id numbers that start with 0. For example, a column of numbers say A1-A3 looks like:
0253980
0253980
0250137
The answer should be "3" but =COUNT(A1:A3) produces "0". This is because the id numbers commence 0. I do not want to convert the numbers because they will be part of other queries later where people need to copy and paste thousands of id numbers into a program which will not work if the 0 is removed.
Is is possible to do a count on these cells?
In Excel what look like numbers are text strings when they start 0 (in general, though numbers may be displayed as preceded with one or more zeros through formatting - all credit to #chris neilsen for reminding me of that!), since Excel automatically strips leading zeros from numeric values. =COUNT:
counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers.
so is not suitable for text strings. However =COUNTA:
Counts the number of cells that are not empty and the values within the list of arguments. Use COUNTA to count the number of cells that contain data in a range or array.
Hence fortunately the solution is very simply to substitute one function for the other and :
=COUNTA(A1:A3)

How can I take a certain characters from a cell of a different spreadsheet

I have a problem with my current code from Excel VBA.
I need to take only the last four digits from another spreadsheet, but it doesn't seem to be possible.
I'm currently using the Sheets("Sheet2").Cells(y, cOTr).Value instruction to take values of other spreadsheets and the LEFT(a,2) and RIGHT(a,2) instructions to take only specific characters of a string data.
I just can't find a way to combine those two instructions.
E.g. I want to copy only the first 4 numbers of Cells from the second column from sheet 2, which has the numbers similar to 6657-2 in it, to sheet 1.
Sorry if my explanation wasn't clear enough.
Edit: Lets's say I want to make a comparison between a table from spreadsheet 1 and a table from spreadsheet 2: the first table has values with four digits (e.g. 3333) and the second has values with 4 digits, a hyphen and another digit (e.g. 2222-3). I need to make a comparison between table 1 and 2, which are from different spreadsheets and to do that I only need the first four digits from table 2. I already have the logic for the program and it's running perfectly with some tests I did with only 4 digit numbers, I only need a way to take those first four numbers, something like using the "left(cells(1,2),2)" instruction but with cells of another spreadsheet.
You can combine text / strings by using the ampersand operator &
e.g.
=LEFT(A2,2) & RIGHT(A2,2)
Alternatively, you can also use CONCATENATE
e.g.
=CONCATENATE(LEFT(A2,2),RIGHT(A2,2),"some other string","and so on")
you can us this formula: =LEFT(Sheet2!A1,4).
Sheet2 A1 is where you have data 2222-3.

Trying to find out how many times numbers come out in a series

I have an excel spreadsheet with number series and I want to count how many times a particular number shows up (i.e. 4)
Attached is a screenprint
!(http://i.imgur.com/kP4EZXv.jpg)
I looked for samples but no one seems to be trying to do the same thing.
Thanks in advance.
Lenny
If your array is in A1:A4, and you want to count the number of times "1" occurs, you would use:
=COUNTIF(A1:A4, "1")
I put random numbers between 0 and 100 in a1 through e5, using =RANDBETWEEN(0,100).
In another column, starting in G6, I put the numbers 1 through 100. Then in H5 I placed the formula =COUNTIF($A$1:$E$5,G6) and filled down.
It kept a count of how many times each number occurred. And every time I entered a new number, the array of numbers would update and the counts would change.
So it looks like your data is all in one column, A1:A24 all two digit numbers (with leading zeroes if required) and with numbers not repeated within individual cells, in which case you can use COUNTIF with a wildcard, e.g. to count "04" try
=COUNTIF(A$1:A$24,"*04*")
or if you want the criteria as a cell value put 4 or 21 or whatever in C2 and use
=COUNTIF(A$1:A$24,"*"&TEXT(C2,"00")&"*")

Excel Random number from a set of options

In MS Excel, how can I randomly calculate a number number that is from one of a set of 5 options?
For example, in cell B1 I would like to have a random number that is either 15,30,50,75, or 100.
I would like a completely random output of these 5 numbers in cells B1:B100.
I was thinking that I could generate a random number in cell A1 using rand, then using a series of > or < IF statements to output only one of these numbers above.
This formula will do it:
=CHOOSE(RANDBETWEEN(1,5),15,30,50,75,100)
If you want to use a range of cells:
=INDEX($B$2:$B$6,RANDBETWEEN(1,5))
A quick and easy way would be to first make a lookup list like this:
Then in your column do a formula like this:
=VLOOKUP(ROUND(RAND()*10,0),$A$7:$B$16,1,FALSE)
where the $A$7:$B$16 is where your list is at. It can be on a different tab, or separate file, if you really need to isolate it.
You could also create a custom VBA function too, but I think that is beyond what you are looking for.
Let's say you have filled rows 1-5 in row G of a spreadsheet with the values you want to randomly display. You can use =INDIRECT("G"&RANDBETWEEN(1,5)) to display any one of those randomly.
`INDIRECT` lets you reference a cell using a string.
Since you want cells "G1" - "G5", we start of with "G".
& combines "G" with the value of the next function.
Then the RANDBETWEEN function will give us a number between the two parameters we provide (in this case 1 through 5).
Let me know if this helps :)
How about:
=SMALL({array containing numbers},RANDBETWEEN(1,COUNT({array containing numbers})))
e.g. if you have an array containing the 5 numbers you want to use in $B$2:$B$6
=SMALL($B$2:$B$6,RANDBETWEEN(1,COUNT($B$2:$B$6)))
This returns a random position in the list of numbers, with the total frequency of numbers being defined size of the array.

Resources