+ Reply to Thread
Results 1 to 11 of 11

VBA to copy specific range

  1. #1
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    VBA to copy specific range

    Hi all

    I'm tyring to write some VBA to copy data from 10 wbs and paste it in a long list one after the other in a different wb on one sheet.
    Copy ranges A2:A34, H2:H34, L2:O34
    Sheet “Project 1(SPT)”
    In wbs: 7aIt1, 7aIt2, 7aIt3, 7aIt4, 7aIt5, 7bIt1, 7bIt2, 7bIt3, 7bIt4, 7bIt5
    AND

    To wb: “2013-14 Autumn KS3 SPT”
    Sheet: “Upload Data”
    In Columns A:F

    Directory T:\Common Area\ICT\Tracking\New Y7

    Does anyone have any suggestions on how to do this?

  2. #2
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    Assuming that your workbooks are closed, I would start with something like this:

    Please Login or Register  to view this content.
    Also, I'm not sure what you mean "In Columns A:F", you are only copying 3 columns, not 6...

    This is untested.

  3. #3
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: VBA to copy specific range

    Hi djdjdj,
    Thank you for your vba! It is correctly opening and closing the wbs when I changed the file type and sheet name, but I cannot get it to copy the ranges in the
    Please Login or Register  to view this content.
    to copy and paste as values in the destination sheet. How can I get it to do this?

    Please Login or Register  to view this content.
    Thank you again! Luke

  4. #4
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    Ah, I think I see the problem. Try changing all of the ws.Range lines from this:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: VBA to copy specific range

    Hi djdjdj,
    I have changed it to
    Please Login or Register  to view this content.
    This is copying the data in column A and column L, but not H or M,N,O.

    It is also pasting from row 34, pasting on top of the data each time it copies it from one of the source wbs (so I end up with the data from 8bIt5).

  6. #6
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    I had set the lastrow variable based on the copy sheet, not the paste sheet! Stupid mistake

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: VBA to copy specific range

    Hi djdjdj,
    No problem Thank you for all your help!

    The code is now correctly copying the columns, but is only taking the first row from each workbook.

  8. #8
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: VBA to copy specific range

    Hi djdjdj,
    WOW! You are a genius! Thank you so much!

    Just a quick thing to tidy it up, what code would I need to delete C:G and I:K in the destination wb - so the empty columns are deleted?

    I'd also like to paste a standard formula in column B - =vlookup(B2,stuid,2,0) where B2 changes based on the row, and some standard headings for Row 1.

    Is the above possible? Thanks again, you've saved me a massive amount of time there!

  10. #10
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    I would setup your workbook format manually before using the code. If you delete columns with your code, your paste destinations will be off next time you run the code because the columns will shift left.

    To add the formula, paste this after the Next j line:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA to copy specific range

    You might have to do double quotes in the formula code...
    Please Login or Register  to view this content.
    but I'm not sure about that. Try both and see which works

+ 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. VBA to copy unique range to specific range area
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-09-2013, 03:53 PM
  2. Copy and paste specific range to date specific range in alternate sheet
    By alanalmarza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 08:29 AM
  3. Copy data in Specific column in a specific range
    By macrofan2012 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2012, 01:27 PM
  4. Copy Specific Cells from Last Row in Range.
    By WinXL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-27-2010, 01:10 PM
  5. Copy Specific Range
    By av3ng3r85 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-29-2006, 06:51 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