2014-12-11 29 views
0

我有成千上萬的會帶我天修改的行和列的殺氣騰騰長的數據表,但我覺得必須有編程有什麼辦法我想要做。不過,我是一個編程小白,很抱歉,如果這很簡單(或不可能)。程序Excel中環路值的一列複製到3分獨立的列

現在我有3列 'V' 'A' 和 'd'。我有一個V A和D值的參與者名單。問題是,參與者的價值在一列中,也就是說,每個參與者的每列中都有90個值。我需要將這90個值分成30'V',30'A'和30'D'值,並複製到它們各自的列中,然後切換到下一個參與者列並執行相同操作。

基本上,我有:

V A D  Participant 1 Participant 2 Participant 3 Etc. 
 
        1    1    1    1 
 
        2    2    2    2 
 
        3    4    3    5 
 
        4    6    9    0 
 
        ...   ...   ...   ... 
 
        90    90    90    90

我需要打破參與者1的90個值(地方先在第V欄30倍的值,在下一30中,d未來30),然後將Excel切換到參與者2將其90個值分爲VA和D列。然後重複這個過程。

在此先感謝您提供的任何建議。

+0

你怎麼知道哪個值對每個參與者屬於任何'V',A''或'D'?你有沒有嘗試過使用「數據透視表」 - 無需代碼? – tospig 2014-12-11 02:12:05

+0

對於每個參與者,第一30倍垂直的值是V,在接下來的30是A,在接下來的30是D.這有可能打破一列到3個不同的列與透視表?我必須做這個過程數百次,所以它必須很容易自動化或循環。 – 2014-12-11 02:16:30

+0

透視表** **可以讓你有,但是這將取決於你如何想用輸出(如果你有與標貼'VV配...,AA的列會更容易.. ,...)'。至於代碼,你是否寫過任何'VBA'? – tospig 2014-12-11 02:22:14

回答

1

此代碼具有兩個for環路,一個用於每個參與者(列),一個用於30個值中的每個塊。它複製第一個參與者的前30個值並將其粘貼到另一個工作表中。然後對30的下一個塊和30的第三個塊重複該操作。然後,外部循環移至下一個參與者。

在這個例子中,我有CB,三個參與者和D在工作表「Sheet2的」,並且數據值開始在行2.輸出被粘貼到「工作表Sheet」,在列開始F

Sub transpose() 

    Dim i As Integer 
    Dim j As Integer 

    Dim outCol As Integer 
    Dim outRow As Integer 
    Dim intStart As Integer 
    Dim intEnd As Integer 
    Dim wksData As Worksheet 
    Dim wksOut As Worksheet 
    Dim strParticipant As String 
    Dim strRange As String 

    Set wksData = Worksheets("Sheet2") 
    Set wksOut = Worksheets("Sheet3") 

    outRow = 2    'starting in row 2 

    For i = 2 To 5   'columns of participants' 

     strParticipant = wksData.Cells(1, i).Value 
     outCol = 6    'output begins in column 6 ("F") 

     For j = 1 To 3  'blocks of values per participant 

      intStart = (j - 1) * 30 + 2 'increment for every block of 30 (starting at row 2) 
      intEnd = intStart + 29 

      wksData.Range(Cells(intStart, i), Cells(intEnd, i)).Copy 
      wksOut.Cells(outRow, outCol).PasteSpecial Paste:=xlValues 

      outCol = outCol + 1 

     Next j 

     'The two lines below will output the participant's name - uncomment if required. 
'   strRange = "E" & outRow & ":E" & outRow + 29 
'   wksOut.Range(strRange) = strParticipant 

     outRow = outRow + 30 'change the output row 

    Next i 

    Set wksData = Nothing 
    Set wksOut = Nothing 

End Sub 
+0

哇!太棒了!我編輯它以適應我的數據,我遇到的唯一問題是輸出是在多個VAD列。我想只有一個V列,一個A和一個D.我該如何去修改這個把它放在同一列? 除此之外,這正是我所需要的,非常感謝你! – 2014-12-11 03:28:54

+0

你的意思是讓所有'V's在同一列,然後所有'A's – tospig 2014-12-11 03:33:53

+0

是的,這就是我想要做的事情,我會做什麼改變? – 2014-12-11 03:35:17

相關問題