我正在尝试将数据从单个单元格拆分为多行,如下所示。
我正在使用下面提到的代码:
Sub TransposeRange()
Dim rng As Range
Dim InputRng As Range, OutRng As Range
xTitleId = "Splitcell"
Set InputRng = Application.Selection.Range("A1")
Set InputRng = Application.InputBox("Range(single cell) :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Arr = VBA.Split(InputRng.Range("A1").Value, Chr(9))
OutRng.Resize(UBound(Arr) - LBound(Arr) + 1).Value = Application.Transpose(Arr)
End Sub
答案1
确保您的输入单元格有水平制表符。您的代码:
Sub TransposeRange()
Dim rng As Range
Dim InputRng As Range, OutRng As Range
xTitleId = "Splitcell"
Set InputRng = Application.Selection.Range("A1")
Set InputRng = Application.InputBox("Range(single cell) :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Arr = VBA.Split(InputRng.Range("A1").Value, Chr(9))
OutRng.Resize(UBound(Arr) - LBound(Arr) + 1).Value = Application.Transpose(Arr)
End Sub
典型结果: