Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 3 of 3

Thread: Copy Paste Alternate Rows without using a loop

  1. #1
    Join Date
    5th September 2005
    Posts
    11

    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 Row.zip)
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    14th July 2004
    Posts
    10,541

    Re: Copy Paste Alternate Rows without using a loop

    Why loop twice?
    VB:
    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 
    Next 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    5th September 2005
    Posts
    11

    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.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Find & Copy Cells & Paste to Alternate Columns
    By billyj in forum EXCEL HELP
    Replies: 10
    Last Post: December 8th, 2006, 12:17
  2. copy & paste in alternate columns
    By qwirky in forum EXCEL HELP
    Replies: 8
    Last Post: June 26th, 2006, 18:27
  3. Copy & Paste Loop
    By zapacoman in forum EXCEL HELP
    Replies: 2
    Last Post: May 12th, 2006, 00:54
  4. VBA: Loop and Copy/Paste
    By mzp in forum EXCEL HELP
    Replies: 6
    Last Post: February 25th, 2006, 04:25
  5. Copy formula to alternate rows
    By PatFlynn17 in forum EXCEL HELP
    Replies: 5
    Last Post: August 6th, 2005, 13:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno