2017-10-23 9 views
-4

enter image description hereEXCEL VBA -

私は助けを事前に

A | B | C 
-----|-------|----- 
    1 | ABC | L 
    1 | ABC | F 
    1 | ABC | M 
    2 | PQR | G 
    2 | PQR | D 
    2 | PQR | S 

おかげで、必要なこの

A | B | C 
-----|-------|------- 
    1 | ABC | L,F,M 
    2 | PQR | G,D,S 

のようなデータを持っている別の列にカンマ区切りの値に変換します。

+0

をお試しください – AntiDrondert

+0

Excel 2010以降をお持ちの場合は、単に 'Power Query'または' Get&Transform'を使用してこれを行うことができます。 –

答えて

2

* *質問は何ですか?この

Sub SplitData() 
    Dim cArray As Variant 
    Dim cValue As String 
    Dim rowIndex As Integer, strIndex As Integer, destRow As Integer 
    Dim targetColumn As Integer 
    Dim lastRow As Long 
    Dim ws As Worksheet 

    targetColumn = 3 'column number with comma separated data 
    Set ws = ThisWorkbook.Worksheets("Sheet1") 'change Sheet1 to your data data 

    destRow = 0 
    With ws 
     lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
     For rowIndex = 1 To lastRow 
      cValue = .Cells(rowIndex, targetColumn).Value 'getting the cell with comma separated data 
      cArray = Split(cValue, ",") 'splitting comma separated data in an array 
      For strIndex = 0 To UBound(cArray) 
       destRow = destRow + 1 
       .Cells(destRow, 5) = .Cells(rowIndex, 1) '5 represents Column E 
       .Cells(destRow, 6) = .Cells(rowIndex, 2) '6 represents Column F 
       .Cells(destRow, 7) = Trim(cArray(strIndex)) '7 represents Column G 
      Next strIndex 
     Next rowIndex 
    End With 
End Sub 

enter image description here