将数据从单列复制到excel中另一个工作表中的多行特定列

时间:2015-04-28 13:16:48

标签: excel-vba vba excel

我在单列Sheet1!A10:A122中有数据。

我想将此数据复制到另一个工作表Sheet2!A14:G14以及A15:G15A16:G16的多行,依此类推,直到Range(A10:A122)中的最后一个非空白单元格。

如何使用vba实现此目的?

2 个答案:

答案 0 :(得分:0)

尝试使用for循环

' Declare worksheets to variables
set ws = ThisWorkbook.Sheets(Sheet1)
set ws2 = ThisWorkbook.Sheets(Sheet2)
' Column Counter (A=1)
h = 1
' Start For loop between lower and upper bound of range (10 to 122)
For i = 10 to 122
    ' If the position of the column on Sheet2 has gone beyond G reset to A and move to next row
    if j > 7 then j = 1: h = h + 1
    ' Copy Data
    ws.cells(i,1) = ws2.cells(h, j)
    ' Move along one column
    j = j + 1
Next i

答案 1 :(得分:0)

我自己得到了问题的答案。这是

{
n = 10
For k = 14 To Sheets("Sheet1").Range("A10:A"&Rows.Count).SpecialCells(xlCellTypeBlanks).Row
    For m = 1 To 7
        Sheets("Sheet2").Cells(k, m) = Sheets("Sheet1").Cells(n, 1)
        n = n + 1
    Next
Next
}