第1个回答 推荐于2016-05-02
只好自定义一个函数啦
按下ALT+F11 插入-模块 输入
Public Function NTON(nTXT As String)
Dim nARR
Dim nStr As String
nARR = Split(nTXT, "-")
For i = nARR(0) To nARR(1)
nStr = nStr & i & ","
Next
NTON = nStr
End Function
然后就可以在表格中像其它函数一样用这个 NTON()了本回答被提问者采纳
第2个回答 2008-01-30
我是假设你这样的数据输入在A1,然后从B1开始横向填充.
按下ALT+F11,插入-模块,复制下代码,然后按F5运行.
Sub aaaa()
Dim a As Integer
Dim b As Integer
a = Val(Left(Cells(1, 1), WorksheetFunction.Find("-", Cells(1, 1)) - 1))
b = Val(Right(Cells(1, 1), Len(Cells(1, 1)) - WorksheetFunction.Find("-", Cells(1, 1))))
Range("b1").Select
For x = a To b
ActiveCell.Value = x
ActiveCell.Offset(0, 1).Select
Next
End Sub
****************
这个是在同一单元格B1中体现
Sub aaaa()
Dim a As String
Dim b As String
Dim sum As String
a = Left(Cells(1, 1), WorksheetFunction.Find("-", Cells(1, 1)) - 1)
b = Right(Cells(1, 1), Len(Cells(1, 1)) - WorksheetFunction.Find("-", Cells(1, 1)))
For x = a To b
sum = sum & x & ","
Next
Range("b1").Select
ActiveCell.Value = sum
End Sub