简体   繁体   中英

Copy and paste value to the next 2 empty row looping

I currently have a code like this

    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

I am trying to make my filenames auto loop to copy another 2 times until the end.

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

I have around 2000 unique jpg files.

You did mistake here, and your range moves right by columns:

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

You need to move it by rows:

 Set rng = rng.Offset(COPY_SIZE + 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM