2014-12-09 4 views
0

제가한 열 세 열로 세 개의 데이터 열로 변환

_A_ _B__ __C__ ___D___ _E_ ____F_____ 
1 Jan 2014 apple 5 units $10 $1.25 cost 
2 Feb 2014 apple 7 units $14 $1.75 cost 

을 다음 I의 값 오프 슬라이서 (즉, 단위 또는 $를 사용하여 필터링 할 수있는 그래프를 생성 할 수있는 데이터 세트를 가지고 에스). 데이터가 다음과 같이 나타나야하지만 조작 방법을 알 수는 없다는 것을 알고 있습니다.

_A_ _B__ __C__ ___D___ __E___ 
1 jan 2014 apple units  5.00 
2 jan 2014 apple $ volume 10.00 
3 jan 2014 apple cost  1.25 
4 feb 2014 apple units  7.00 
5 feb 2014 apple $ volume 14.00 
6 feb 2014 apple cost  1.75 

답변

0

상위 데이터 세트가있는 시트의 버튼에 다음 매크로를 지정하십시오. 버튼을 클릭하면 (매크로가 지정되면) 하단 행으로 변환됩니다. 모든 문제는 답변하십시오.

Sub SortData() 
    ' Assign the following macro to a button or shape to achieve your result 
    Dim StartingSheet, val As String 
    StartingSheet = ActiveSheet.Name 

    With Sheets.Add 
     For i = 1 To Sheets(StartingSheet).Cells(Rows.Count, 1).End(xlUp).Row 
      For j = 1 To 3 
       .Cells(((i - 1) * 3 + (j Mod 3) + 1), 1).Value = Sheets(StartingSheet).Cells(i, 1).Value 
       .Cells(((i - 1) * 3 + (j Mod 3) + 1), 2).Value = Sheets(StartingSheet).Cells(i, 2).Value 
       .Cells(((i - 1) * 3 + (j Mod 3) + 1), 3).Value = Sheets(StartingSheet).Cells(i, 3).Value 
       If j = 1 Then 
        val = "$ volume" 
        .Cells(((i - 1) * 3 + (j Mod 3) + 1), 5).Value = Replace(Sheets(StartingSheet).Cells(i, 5).Value, "$", "") 
       End If 
       If j = 2 Then 
        val = "cost" 
        .Cells(((i - 1) * 3 + (j Mod 3) + 1), 5).Value = Replace(Replace(Sheets(StartingSheet).Cells(i, 6).Value, "$", ""), " cost", "") 
       End If 
       If j = 3 Then 
        val = "units" 
        .Cells(((i - 1) * 3 + (j Mod 3) + 1), 5).Value = Replace(Sheets(StartingSheet).Cells(i, 4).Value, " units", "") 
       End If 
       .Cells(((i - 1) * 3 + (j Mod 3) + 1), 4).Value = val 
      Next 
     Next 
    End With 

End Sub 
관련 문제