+ Reply to Thread
Results 1 to 6 of 6

VBA Loop not pasting in teh correct location

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    VBA Loop not pasting in teh correct location

    Hi

    I have this bit of code which does multiple things, it opens a two files and pastes data from one to other and then adds th values to a sheet in that workbook. It then should loop through a folder and copy the data range A2:M14 and paste it into the template workbook on the identified sheet in the cell B2 and then close the file and open the next and paste the data range under the data there but also leaving a white line between them.

    However currently it wont loop as it pulls an error at the highlighted line below and also does not copy and paste the correct data.

    Please Login or Register  to view this content.
    Can anyone work out why it is not running?

    Thanks

    Jeskit
    Last edited by jeskit; 04-01-2011 at 05:58 AM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA Loops

    jeskit,

    Here's the section of your code that loops:

    Please Login or Register  to view this content.



    It looks like you want to loop through all the files in a directory until there aren't anymore files. Here's the code for how to do that:

    Please Login or Register  to view this content.


    Hope this helps,
    ~tigeravatar
    Last edited by tigeravatar; 03-31-2011 at 04:10 PM. Reason: typo

  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: VBA Loops

    Hi

    Thank you for replying but i need it not only loop through the folder but i need to open the files that match strFile variable and copy the range A2:M14 and paste it into the template workbook in the settings sheet in B2 but when it goes the next file i need to paste it under the data there but leaving a blank line between them.

    Currently i cant get it to copy the right data and paste into the right location. If you have any ideas it would be extremely helpful

    Thanks
    Last edited by jeskit; 04-01-2011 at 02:58 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Loops

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    YOUR TITLE SHOULD GIVE AN INDICATION OF THE PROBLEM< NOT A VAGUE REFERENCE TO LOOPS
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: VBA Loop not pasting in teh correct location

    Sorry i forgot....i have changed it now.....however when i saw someone replied i was hoping for a solution

  6. #6
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: VBA Loop not pasting in teh correct location

    Hi

    Thanks to all who helped but i have fixed it.... i changed this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.

+ 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