+ Reply to Thread
Results 1 to 5 of 5

Macro Looping and Copy

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    4

    Macro Looping and Copy

    Hi I am a little stuck with attempting to loop through a list of rows in excel.

    With my data below I would like to loop though all the rows and then if certain columns are not blank, copy and loop through.


    Using my table below i would like to look at row 1 and then loop through each value in col D to G.
    If the column has a value, copy col A to C into a new row and add the first item in the loop(D in this case) then do this for the rest (E to G).

    I should also note that I do have it working to loop through all of ColA down until the colA is blank.

    What I am stuck on is how to select those rows. How would I select and loop through these values and then how do i move the row(including my new selection row) to the next.

    Ie. Row 1 ---- loop through all values in Row 1 col D to G then move to Row 2 and loop through col D to G in row 2?

    Thanks.

    ColA ColB ColC ColD ColE ColF ColG
    aaa ddd gg hh h
    bbb eee dd
    ccc fff hh jj
    ddd ggg ee s
    eee hhh ff ff ff

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro Looping and Copy

    Please Login or Register  to view this content.
    The code here loops through columns A to G or 1 to 7 and row 1 to the last row in column A. It checks the value of each cell in that range. (So A1 to G & last_Row) If it finds some value it does whatever you want in that for loop. This hopefully gives you a general idea of how things work in VBA.

    Your explanation of exactly what you want wasn't that clear to me. Also, you can attach a sample workbook if you need to show an example of what you are doing instead of formatting here.

  3. #3
    Registered User
    Join Date
    04-12-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro Looping and Copy

    Hi, sorry about my confusing description. I've attached a worksheet that shows what i'm refering to more clearly.

    Thanks for your help!test.xlsm

  4. #4
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro Looping and Copy

    Please Login or Register  to view this content.
    Hopefully it is self explanatory. You choose which columns you check. Also, I call sheet 1 "Main" and put the data onto "Unique" or sheet 2. So in your example I erase the copy data before running the macro.

  5. #5
    Registered User
    Join Date
    04-12-2012
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro Looping and Copy

    I actually got mine working before I saw your last post.
    Ended up going through in a similar way and it does the trick.

    Thanks for being willing to help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1