回復 2#joey0415
請參考參考
Sub Ex()
Dim Rng As Range, A, B, W, E
W = "111,222,333,444 AAAA,BBB,CCC,DDDD"
A = Split(W, " ") '以空白分解
Set Rng = [A1]
Rng.CurrentRegion = ""
For Each E In A
B = Split(E, ",") '以 , 分解
'''''''''''橫排
Rng.Resize(1, UBound(B)+1) = B '陣列是橫排的
Set Rng = Rng.Offset(1)
'''''''''''直排
'Rng.Resize(UBound(B)+1, 1) = Application.Transpose(B) 'Transpose轉置為直排
'Set Rng = Rng.Offset(, 1)
Next
End Sub作者: oobird 時間: 2010-10-13 21:42
Sub Macro1()
t = [a1]
sp = Split(t, " ")
p1 = Split(sp(0), ",")
p2 = Split(sp(1), ",")
For i = 1 To 4
Cells(1, 2 + i) = p1(i - 1)
Cells(2, 2 + i) = p2(i - 1)
Cells(i, 8) = p1(i - 1)
Cells(i, 9) = p2(i - 1)
Next
End Sub作者: joey0415 時間: 2010-10-13 22:47
感謝兩位版主幫忙,小弟應該會用了,謝謝作者: lasum 時間: 2012-6-26 02:59
最近在學習VBA…上述的程式都有測試…
oobird 大的程式會出現 陣列索引超出範圍 錯誤 9
不知道是不是版本的問題…我來找到了這篇 http://forum.twbts.com/redirect. ... amp;goto=nextoldset
修改後的程式如下…
Sub Macro1()
On Error Resume Next '增加程式
t = [a1]
sp = Split(t, " ")
p1 = Split(sp(0), ",")
p2 = Split(sp(1), ",") '修改前會出現 陣列索引超出範圍 錯誤 9
For i = 1 To 4
Cells(1, 2 + i) = p1(i - 1)
Cells(2, 2 + i) = p2(i - 1)
Cells(i, 8) = p1(i - 1)
Cells(i, 9) = p2(i - 1)
Next
End Sub
爾後程式就正常了…感謝以上前輩提供的學習資料!作者: GBKEE 時間: 2012-6-26 09:38