程序Excel循环将一列值复制到3个单独的列中

我有一个长长的数据表,上面有成千上万的行和列,需要几天的时间才能编辑,但我觉得必须有一种方法来编写我想要做的事情。 不过,我是一个编程小白,很抱歉,如果这是简单的(或不可能的)。

现在我有3列“V”“A”和“D”。 我有一个VA和D值的参与者名单。 问题是,参与者的价值是在一个列中,也就是说,每个参与者在每个列中有90个值。 我需要将这90个值分成30个“V”,30个“A”和30个“D”值,并复制到各自的列中,然后切换到下一个参与者列并执行相同操作。

基本上,我有:

VAD 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个值,在A中下30个,在D中下30个),然后将Excel切换到参与者2将其90个值分成VA和D列。 然后重复这个过程。

预先感谢您提供的任何build议。

此代码有两个for循环,每个参与者(列)一个,每个30个值的块。 它复制第一个参与者的前30个值并将其粘贴到另一个工作表上。 然后对30的下一个块和30的第三个块重复该操作。外部循环然后移动到下一个参与者。

在这个例子中,我在工作表“Sheet2”的列BCD有三个参与者,数据值从第2行开始。输出被粘贴到“Sheet3”,从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