例如,我有一个名为str的字符串变量。该str的值为:
apple
orange
pineapple
每个单词由newVbLine分隔。我想把它移到细胞上。 A1包含apple
,A2包含orange
,A3包含pineapple
。
感谢。
答案 0 :(得分:5)
下面的代码将A列中由vbNewLine
分隔的字符串拆分为B列。
请更改
ws1.[b1].Resize(UBound(X) - LBound(X) + 1, 1) = Application.Transpose(X)
到
ws1.[a1].Resize(UBound(X) - LBound(X) + 1, 1) = Application.Transpose(X)
如果要覆盖A列
Sub Spliced()
Dim ws1 As Worksheet
Dim X
Set ws1 = Sheets(1)
X = Split(Join(Application.Transpose(ws1.Range(ws1.[a1], ws1.Cells(Rows.Count, "A").End(xlUp))), vbNewLine), vbNewLine)
ws1.[b1].Resize(UBound(X) - LBound(X) + 1, 1) = Application.Transpose(X)
End Sub