简体   繁体   中英

Excel - Split apart a list

I have a list of about 300 items, that I need spaced out every 8 cells as opposed to being one after the other. I'm sure there is an easy way to do this, however my brain is failing me. I have a feeling my terminology is hurting hence why I can't find an answer.

在此输入图像描述

=IF(MOD(ROW()+7;8)=0;INDEX(A:A;INT(ROW()/8)+1);"")

假设数据从A1开始,并且从第1行使用公式(coulmn并不重要)。

Try below code

Sub Main()


    Dim lastRow As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To lastRow
        If i = 1 Then
            Cells(i, 5).Value = Cells(i, 1)
        Else
            Cells((i - 1) * 9, 5).Value = Cells(i, 1)
        End If
    Next

End Sub

Output

在此输入图像描述

Can you please post a screen shot or add some additional detail?

Two things come to my mind for possible solutions:

1) Use Text to columns (if that is where you're going with this) or

2) Use a formula like =LEFT(A1, 10) in the 8th column and fill down (10 can be changed to whatever the first part of the string is that needs to be separated).

Provide some additional info and I'll take another look!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM