No announcement yet.

Copy Paste Alternate Rows without using a loop

  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy Paste Alternate Rows without using a loop

    I have tried searching the forum for any relevant thread but no similar issue was found.

    I would like to ask if there is a possibility to select a range of cells with alternating rows?

    My existing program uses a loop, and I think it is not a good idea using a loop.

    Thank you very much for your help!

    Please see the attached file.(Copy Alternate
    Attached Files

  • #2
    Re: Copy Paste Alternate Rows without using a loop

    Why loop twice?
    Dim rows As Long
    Dim rowCtr As Long
    Dim rowCtr2 As Long
    Const startRow1 = 4
    Const startRow2 = 5
        rows = Sheets("Sheet1").UsedRange.rows.Count
        rowCtr2 = 2
        Sheets("Cash").Range("A1").Value = Sheets("Sheet1").Range("A3").Value
        Sheets("Cash").Range("B1:M1").Value = Sheets("Sheet1").Range("E3:P3").Value
        Sheets("Credit").Range("A1").Value = Sheets("Sheet1").Range("A3").Value
        Sheets("Credit").Range("B1:M1").Value = Sheets("Sheet1").Range("E3:P3").Value
        For rowCtr = startRow1 To rows Step 2
           Sheets("Cash").Range("A" & rowCtr2).Value = Sheets("Sheet1").Range("A" & rowCtr).Value
           Sheets("Cash").Range("B" & rowCtr2 & ":M" & rowCtr2).Value = Sheets("Sheet1").Range("E" & rowCtr & ":P" & rowCtr).Value
           Sheets("Credit").Range("A" & rowCtr2).Value = Sheets("Sheet1").Range("A" & rowCtr).Value
           Sheets("Credit").Range("B" & rowCtr2 & ":M" & rowCtr2).Value = Sheets("Sheet1").Range("E" & rowCtr + 1 & ":P" & rowCtr + 1).Value
           rowCtr2 = rowCtr2 + 1


    • #3
      Re: Copy Paste Alternate Rows without using a loop

      Thank you very much norie.
      Yeah, why loop twice?

      This would help the performance of my program.

      If there is no way of not using a loop, I guess I would just use your suggestion.
      I also tried searching from the internet, and I don't know if there's a relationship of using an Offset. I am not yet familiar with the correct syntax of Offset.

      Thank you very much for sharing your precious time.