如何在不使用转置的情况下垂直列出水平数据?

时间:2019-08-15 17:26:22

标签: excel vba excel-formula

Excel picture here explains this best.

我得到了一个导出的电子表格,该表格具有一个单元格中的数据,并用“ ALT + ENTER”分隔。我希望此数据垂直在每一行上,而不是在单个单元格中。

我试图通过“ CTRL + J”将它们分隔成列。我认为这可能会更容易垂直列出(逐行)。您可以看到我要去的地方

here

我尝试了一些在网上找到的VBA,但我对此一无所知。如果我想找出解决这个问题的VBA解决方案,那会花我更长的时间,因为我不太了解。

我尝试过:
    Sub vertsplit() Dim xRg As Range Dim xOutRg As Range Dim xCell As Range Dim xTxt As String Dim xStr As String Dim xOutArr As Variant On Error Resume Next xTxt = ActiveWindow.RangeSelection.Address Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8) If xRg Is Nothing Then Exit Sub Set xOutRg = Application.InputBox("please select output cell:", "Kutools for Excel", , , , , , 8) If xOutRg Is Nothing Then Exit Sub For Each xCell In xRg If xStr = "" Then xStr = xCell.Value Else xStr = xStr & "," & xCell.Value End If Next xOutArr = VBA.Split(xStr, ",") xOutRg.Range("A1").Resize(UBound(xOutArr) + 1, 1) = Application.WorksheetFunction.Transpose(xOutArr) End Sub

我用逗号替换了“ ALT + ENTERS”,然后尝试了上面的代码,但是它不适用于多个单元格。

FUNCTION SOLUTION ERROR

2 个答案:

答案 0 :(得分:2)

如果您具有Office 365 Excel,则可以使用TEXTJOIN创建一行文本并对其进行解析:

=TRIM(MID(SUBSTITUTE(TEXTJOIN(CHAR(10),TRUE,$A$1:$A$4),CHAR(10),REPT(" ",999)),(ROW(1:1)-1)*999+1,999))

enter image description here

答案 1 :(得分:1)

Excel 2010+,您可以使用Power QueryGet & Transform

  • 在列中选择一个单元格
  • 从表/范围获取数据
  • 由#lf分成几行

enter image description here

enter image description here