2017-12-18 14 views

答えて

0

すべてのこれらの値は、シート1である場合は、単純に、このコードは、あなたが期待する何でしょう、あなたはあなたの結果のためのSheet2を持っていることを確認してください:

私が欲しい

Column A  Column B    Column C 
Electrical Lighting,Thunder  Bad,Good 
Mechanical Nut, Bolt   Bad,Good 

結果

EDIT:

それは今あまりにも単一の値のために動作します

Sub foo() 
Dim LPosition As Integer 'declare variables 
Dim LPosition2 As Integer 
Dim LastRow As Long 
Dim NextEmptyRow As Long 
Dim strName As String 
Dim TempArray1() As String 
Dim TempArray2() As String 

LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row 'find the last row on column A on Sheet1 
For i = 2 To LastRow 'loop from row 2 to the last row 
    strName = Sheet1.Cells(i, 1).Value 'get the value of Column A into a variable 
    LPosition = InStr(Sheet1.Cells(i, 2).Value, ",") ' check if Columm B has a comma in it 
    If LPosition > 0 Then 
     TempArray1 = Split(Sheet1.Cells(i, 2).Value, ",") 'if comma found put values into an array 
    Else 
     TempArray1(0) = Sheet1.Cells(i, 2).Value 
    End If 

    LPosition2 = InStr(Sheet1.Cells(i, 3).Value, ",") 'check for a comma on Column C 
    If LPosition2 > 0 Then 
     TempArray2 = Split(Sheet1.Cells(i, 3).Value, ",") 'place values into a separate Array 
    Else 
     TempArray2(0) = Sheet1.Cells(i, 3).Value 
    End If 
    For x = 0 To UBound(TempArray1) 'loop through the array 
     NextEmptyRow = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row + 1 'check the next free row on Sheet2 
     Sheet2.Cells(NextEmptyRow, 1).Value = Trim(strName) 'place appropriate values 
     Sheet2.Cells(NextEmptyRow, 2).Value = Trim(TempArray1(x)) 
     Sheet2.Cells(NextEmptyRow, 3).Value = Trim(TempArray2(x)) 
    Next x 
    ReDim TempArray1(0) 
    ReDim TempArray2(0) 
Next i 
End Sub 
+0

この@XABierで私を助けてくれてありがとう、Col BとCol Cが各行に複数の値を持つとき、これはうまく動作します。 Col BとCol Cには単一の値しか持たない行があり、そのまま存在するはずです。それに取り組む方法はありますか? –

+0

@ M.Rafi私は私の答えを更新しました、それは今も単一の値で動作するはずです。 – Xabier

関連する問題