Make a sequence between two numbers

Robert Davidson

New Member
Joined
Aug 8, 2023
Messages
29
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Does anyone know how to make a sequence of number as follows:

Start between 1 & 15, increment either in 5 or 10 but always ending at 100?
For example Start at 5 and increment in 10s: 5,15,25,35,45,55,65,75,85,95,100
For some sequences it's easy starting at 5 and incrementing in 5s as it can always stop at 100 but how do I deal with the above situation where the balance between 95 and 100 is not the same as the increment?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,

It's easy :) Assuming you have your first value in A1,
A2 formula will be:
Excel Formula:
=IF(A1+10>100,100,A1+10)
Drag down the formula.
 
Upvote 0
Try this macro on a blank sheet.
VBA Code:
Sub CreateSequence()
    Application.ScreenUpdating = False
    Dim x As Long, start As String, incr As String, lRow As Long
    start = InputBox("Enter the starting number.")
    If start = "" Then Exit Sub
    incr = InputBox("Enter the increment.")
    If incr = "" Then Exit Sub
    For x = start To 100 Step incr
        Cells(Rows.Count, "A").End(xlUp).Offset(1) = x
    Next x
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Range("A" & lRow) <> "100" Then
        Cells(Rows.Count, "A").End(xlUp).Offset(1) = "100"
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
How about
Fluff.xlsm
ABC
1
2Start55
3Increment1015
425
535
645
755
865
975
1085
1195
12100
13
Sheet8
Cell Formulas
RangeFormula
C2:C12C2=LET(s,SEQUENCE(CEILING((101-B2)/B3,1),,B2,B3),IF(MAX(s)=100,s,VSTACK(s,100)))
Dynamic array formulas.
 
Upvote 0
Wow, I need to refresh these pages sooner. Was going to say that nothing was mentioned about the output requirements but if OP wanted code, here's one that builds a string of numbers. Might as well post it. The key (for me) was to use a Do While loop so that the test could be made at the start of the loop. I didn't try to think about how to deal with the fact that in a For Next loop, the To value is static, which can make it not really useful in comparing sums.
VBA Code:
Function Sequences(intStart As Integer, intIncrement As Integer) As String
Dim i As Integer

i = intStart
Sequences = intStart
Do While i + intIncrement < 100
    Sequences = Sequences & "," & i + intIncrement
    Debug.Print Sequences
    i = i + intIncrement
Loop
If Right(Sequences, 3) <> "100" Then
    Sequences = Sequences & ",100"
End If
Debug.Print Sequences
End Function
 
Upvote 0
Another possible formula option.

24 01 09.xlsm
ABC
1
2Start55
3Increment1015
425
535
645
755
865
975
1085
1195
12100
13
Sequence
Cell Formulas
RangeFormula
C2:C12C2=LET(s,SEQUENCE(20,,B2,B3),VSTACK(FILTER(s,s<100),100))
Dynamic array formulas.
 
Upvote 1
Solution
Another possible formula option.

24 01 09.xlsm
ABC
1
2Start55
3Increment1015
425
535
645
755
865
975
1085
1195
12100
13
Sequence
Cell Formulas
RangeFormula
C2:C12C2=LET(s,SEQUENCE(20,,B2,B3),VSTACK(FILTER(s,s<100),100))
Dynamic array formulas.
Thank you Peter, This one is my preferred solution. Robert
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top