答案1
在 Office 365 中:
C1: =TEXTJOIN(", ",TRUE,SEQUENCE(B1-A1+1,,A1))
编辑:如果您需要在早期版本的 Excel 中使用它,并且您的输入是一个带连字符的字符串(如您在注释中的示例所示)表示开始和结束数字,请尝试:
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
例如:Consec("33-40")
=>33, 34, 35, 36, 37, 38, 39, 40