如何在每个下一个单元格中按3-3的组划分多个单元格?

时间:2019-04-05 10:25:11

标签: excel vba excel-formula

enter image description here

如上图所示,我有一列,其中包含许多用逗号分隔的数字。我需要在每个下一个单元格中将这些数字按3-3分组。

2 个答案:

答案 0 :(得分:0)

尝试一下:

Option Explicit

Sub test()

    Dim str As String
    Dim Appears As Long, i As Long, Times As Long, LastColumn As Long, StartPoint As Long, EndPoint As Long

    With ThisWorkbook.Worksheets("Sheet1")

        str = .Range("A1").Value & ","

        Times = 0

        StartPoint = 1

        For i = 1 To Len(str)

            If Mid(str, i, 1) = "," Then

                Times = Times + 1

                If CDbl(Times / 3) = Round(CDbl(Times / 3)) Then

                    EndPoint = i

                    LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column

                    .Cells(1, LastColumn + 1).Value = Mid(str, StartPoint, EndPoint - StartPoint)

                    StartPoint = EndPoint + 2

                End If

            End If

        Next i

    End With

End Sub

答案 1 :(得分:0)

所以,虽然很残酷但确实可以:

=LEFT(A1,FIND(",",A1,FIND(",",A1,FIND(",",A1,1)+1)+1)-1)

您可以使用MID()和RIGHT()来获得其他人。...

请参阅 enter image description here