For example, I have 33 in cell A1, and 40 in cell B1, I want a formula in cell C1, to write an arithmetic sequence from 33 to 40 like this: 33, 34, 35, 36, 37, 38, 39, 40
Asked
Active
Viewed 45 times
1 Answers
0
In Office 365:
C1: =TEXTJOIN(", ",TRUE,SEQUENCE(B1-A1+1,,A1))
Edit: If you need to use this in an earlier version of Excel, and your input is a hyphenated string (as you show in your example in your comment) denoting the start and end numbers, try:
Option Explicit
Function Consec(ln As String) As String
Dim v As Variant, w As Variant
Dim L As Long, E As Long
w = Split(ln, "-")
L = w(0)
E = w(1)
ReDim v(L To E)
For L = L To E
v(L) = L
Next L
Consec = Join(v, ", ")
End Function
eg: Consec("33-40") => 33, 34, 35, 36, 37, 38, 39, 40
phuclv
- 30,396
- 15
- 136
- 260
Ron Rosenfeld
- 9,461

