将一行分成几行

我有一行包含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