将一行分成几行

Split one row into several rows

我有一行包含 5000 个单元格,我想将此数据分成几行(每行 4 个单元格)。

有没有自动化的方法?

示例: 由此 123412341234

对此
1234
1234
1234

使用的程序是Excel

问候

如果您连续有 5000 个单元格,并且您希望每 4 个单元格拆分并在一列中输出,则此代码将起作用。

Sub splitInCols()
Dim inputRow As Long, nCol As Long, lastCol As Long, iRow As Long
Dim sht As Worksheet
Set sht = ActiveSheet

inputRow = 1 'Put your row number here
outputCol = 1 'The column where it will output
lastCol = sht.Cells(inputRow, sht.Columns.Count).End(xlToLeft).Column

iRow = 2    'Row start of your output
n = 0
For j = 1 To lastCol
    If n < 4 Then
        splitText = splitText & Cells(inputRow, j).Value
        n = n + 1
    End If
    If n = 4 Or j = lastCol Then
        Cells(iRow, outputCol).Value = splitText
        iRow = iRow + 1
        n = 0
        splitText = ""
    End If
Next
End Sub