将值复制并粘贴到下一个空行循环中

时间:2017-11-17 09:31:27

标签: excel excel-vba excel-formula vba

我目前有这样的代码

    Sub Rowname()

    Const SHEET_NAME As String = "Sheet1"
    Const START_ROW As String = "A"
    Const ROW_NUM As Long = 1
    Const COPY_SIZE As Integer = 2
    Dim rng As Range


    Set rng = ThisWorkbook.Worksheets(SHEET_NAME).Cells(ROW_NUM, START_ROW)
    Do Until IsEmpty(rng)
    rng.Offset(1, 0).Resize(COPY_SIZE, 1) = rng.Value2
    Set rng = rng.Offset(, COPY_SIZE + 1)
    Loop

    End Sub

我正在尝试将我的文件名自动循环复制另外2次直到结束。

    |  A    |         to something like  |  A    |
    |123.jpg|                            |123.jpg|
    |       |                            |123.jpg|
    |       |                            |123.jpg|
    |456.jpg|                            |456.jpg|
    |       |                            |456.jpg|
    |       |                            |456.jpg|

我有大约2000个独特的jpg文件。

1 个答案:

答案 0 :(得分:0)

你在这里犯了错误,你的范围按列移动:

Set rng = rng.Offset(, COPY_SIZE + 1)

您需要按行移动它:

 Set rng = rng.Offset(COPY_SIZE + 1)