+ Reply to Thread
Results 1 to 4 of 4

Conflict when combining 2 loops

  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2007
    Posts
    9

    Post Conflict when combining 2 loops

    Hi everyone,

    I have a master workbook (named "consolidated") where I need to run a macro that:
    - opens one after the other 8 workbooks of a folder selected by the user
    - copy data from each workbook to a corresponding sheet in the master workbook

    For example:
    Open 1st workbook of the folder and copy data of activate sheet to sheet8 of the master book
    Open 2nd workbook of the folder and copy data of activate sheet to sheet9 of the master book
    etc... until 8th workbook and sheet16

    For that purpose, I am using a code with "Do / Loop" to open the files of selected folder and "For i = 9 to 16 / Next i" to copy data and move to the next worksheet.

    Please Login or Register  to view this content.
    My problem is that I cannot combine these 2 loops, they only run one after the other.

    Can anyone help me with my code?

    Thanks in advance

    Figolu

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Conflict when combining 2 loops

    I think you've got the loops the wrong way round.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Conflict when combining 2 loops

    You only copy one worksheet per workbook, right? So you don't need two loops.

    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.


    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    10-29-2013
    Location
    Barcelona, Spain
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Conflict when combining 2 loops

    Thank you very much yudlugar & OllyXLS

    @yudlugar: code works well but the loop to paste data goes twice and it overwrites data

    @OllyXLS: code works perfectly! You are right, only one loop is necessary, maybe that's why the combination of 2 loops overwrites data

    Thanks again to both of you, you've been my greatest help!

    Figolu

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Worksheet_Change conflict
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-02-2010, 04:13 PM
  2. conflict name box R1C1
    By dvb_24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2010, 07:49 AM
  3. PC-Mac Conflict
    By dcassell in forum Excel General
    Replies: 0
    Last Post: 01-21-2008, 02:26 PM
  4. Conflict with Workbooks
    By kartune85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2006, 01:50 AM
  5. [SOLVED] ToolBar Conflict
    By TK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2005, 04:10 PM

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