本文介绍了将一行分成几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一行包含5000个单元格,我想将此数据分成几行(每行4个单元格).
I have one row that contains 5000 cells and I want to split this data into several rows (4 cells per row).
有自动的方法吗?
示例:由此123412341234
Example:From this123412341234
对此
1234
1234
1234
To this
1234
1234
1234
使用的程序是Excel
Program used is Excel
致谢
推荐答案
如果您连续有5000个单元格,并且希望每4个单元格拆分一次并在列中输出,则此代码将起作用.
This code will work if you have 5000 cells in a row and you want to split at every 4 cells and output in a column.
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
这篇关于将一行分成几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!