Casey
Casey

Reputation: 55

Formula for generating delimited list of incremented numbers

Looking for a formula that takes a min and max value, then generates a delimited list of numbers including and between those values.

For example:

min = 2015

max = 2017

result = 2015,2016,2017

Not sure what to call it/how to word it, everything I've tried gives me results unrelated.

Upvotes: 1

Views: 71

Answers (2)

Casey
Casey

Reputation: 55

After help from @Mayukh Bhattacharya, I was able to accomplish my desired output by using his suggested macro for SEQUENCE alone.

Function SEQUENCE(min As Integer, max As Integer, steps As Integer) As String
  Dim i As Integer
  For i = min To max Step steps
    SEQUENCE = SEQUENCE & i & ","
  Next i
  SEQUENCE = Left(SEQUENCE, Len(SEQUENCE) - 1)
End Function

Written as =SEQUENCE(1987,1990,1) gave me 1987,1988,1989,1990

Upvotes: 2

Mayukh Bhattacharya
Mayukh Bhattacharya

Reputation: 27338

You may try

=TEXTJOIN(",",,SEQUENCE(1,3,2015,1))

Upvotes: 1

Related Questions