EXCEL VBA的问题将某单元格的数据存入数组
比如某单元格里101,110,115-120存入数组的为101110115116117118119120...
比如某单元格里101,110,115-120
存入数组的为101 110 115 116 117 118 119 120 展开
存入数组的为101 110 115 116 117 118 119 120 展开
1个回答
展开全部
sheets("表名").cells(行号,列号)可获得单元格的值,其中行列号都是数字
Function bbb(b)
Dim a()
b = b & ","
i = 1
j = -1
ks = 1
js = 1
ifg = False
Do While Len(b) >= i
If Mid(b, i, 1) = "," Then
j = j + 1
ReDim Preserve a(j)
ks = js
js = i + 1
If Not ifg Then
a(j) = Mid(b, ks, js - ks - 1)
Else
m = Mid(b, ks, js - ks)
j = j + js - ks + 1
ReDim Preserve a(j)
For m = j + ks - js - 1 To j - 1
a(m) = a(m - 1) + 1
Next
End If
ElseIf Mid(b, i, 1) = "-" Then
j = j + 1
ReDim Preserve a(j)
ks = js
js = i + 1
a(j) = Mid(b, ks, js - ks - 1)
ifg = True
End If
i = i + 1
Loop
Sheet3.Cells(1, 1) = ""
For i = 0 To UBound(a)
c = c & " " & a(i)
bbb = c
Next
End Function
应该会用吧?是在代码里调用的
例如
Sheet3.Cells(1, 1) = bbb(Sheet3.Cells(1, 2))
原始数据时在Sheet3.Cells(1, 2)里,数据要输出在Sheet3.Cells(1, 1) 里
Function bbb(b)
Dim a()
b = b & ","
i = 1
j = -1
ks = 1
js = 1
ifg = False
Do While Len(b) >= i
If Mid(b, i, 1) = "," Then
j = j + 1
ReDim Preserve a(j)
ks = js
js = i + 1
If Not ifg Then
a(j) = Mid(b, ks, js - ks - 1)
Else
m = Mid(b, ks, js - ks)
j = j + js - ks + 1
ReDim Preserve a(j)
For m = j + ks - js - 1 To j - 1
a(m) = a(m - 1) + 1
Next
End If
ElseIf Mid(b, i, 1) = "-" Then
j = j + 1
ReDim Preserve a(j)
ks = js
js = i + 1
a(j) = Mid(b, ks, js - ks - 1)
ifg = True
End If
i = i + 1
Loop
Sheet3.Cells(1, 1) = ""
For i = 0 To UBound(a)
c = c & " " & a(i)
bbb = c
Next
End Function
应该会用吧?是在代码里调用的
例如
Sheet3.Cells(1, 1) = bbb(Sheet3.Cells(1, 2))
原始数据时在Sheet3.Cells(1, 2)里,数据要输出在Sheet3.Cells(1, 1) 里
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |