+ Reply to Thread
Results 1 to 7 of 7

Copy selected worksheets between workbooks onto named worksheets

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    9

    Copy selected worksheets between workbooks onto named worksheets

    Hi,

    New to VBA and this is my first shot at some code. Trying to cycle through a user specified directory for all excel workbooks. It is going to copy two sheets from each of these workbooks back into the ConsolidatedWorkbook. Each workbook has a unique name, which i have set up as a worksheet on the main ConsolidatedWorkbook. In an ideal world, it would check if the sheet existed first. If not, create one.

    All of Sheet 3 is copied over, but only a selection from sheet 2.

    MY below code worked the first time i ran it, but now fails to run.

    All help and suggestions welcome...like i say, first crack at coding in VBA so go easy.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi Andrew

    Welcome to the Forum!!

    Where (or how) is it failing?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi,

    Thanks for the quick reply. Seems to be failing here on the first copy...


    MyFolder = GetFolder("C:\", "Select an Input Folder")
    MyFile = Dir(MyFolder & "\*.xls")
    Do While MyFile <> ""
    Workbooks.Open filename:=MyFolder & "\" & MyFile
    Set sourceBook = Workbooks(MyFile)


    Windows(MyFile).Activate
    Sheets("Sheet3").Select
    Cells.Select
    Selection.Copy

    Get a runtime error as if there is no selection made prior to the copy. However, when you step into this you can see the correct sheet is "selected" ready to copy.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi Andrew

    Please use Code Tags around any Code you post.

    Your Code could do with a bit of surgery but this Line of Code, I suspect, is the one that's failing
    Please Login or Register  to view this content.
    It should probably read
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-08-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi,

    Apologies. In my excitement at getting a reply so quick, I forgot to wrap my code in the appropriate tags. Noted for the future.

    Tried your suggestion, but still failing at the same section.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi Andrew

    I'll need to see your File(s) in order to trouble shoot.

    Please attach the Workbook the Code Runs from (include the Code in the Workbook) and attached 2 or 3 examples of the Files you'll be extracting Data from.

    The structure of your attachments should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet that demonstrates what you wish the output to be.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the "Upload Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.

  7. #7
    Registered User
    Join Date
    01-08-2014
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Copy selected worksheets between workbooks onto named worksheets

    Hi,

    Apologies for the delay.

    Unfortunately, these are accounts files which I am unable to share here. I have, however, set up a sheet which might better explain what i am attempting to do. Hopefully you can better follow my logic.

    If you really cannot help without the full files, i understand. And I appreciate your time thus far.

    If you could think of an easier approach to this problem, i welcome your suggestions.
    Attached Files Attached Files

+ 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. copying similar named worksheets from multiple workbooks into a master workbook
    By bradpeh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2013, 04:41 AM
  2. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  3. copy selected range from multiple workbooks into multiple worksheets in one workbook
    By novak100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2012, 05:52 AM
  4. Replies: 0
    Last Post: 07-26-2010, 09:41 PM
  5. Need macro to copy a list of named cells between worksheets
    By John in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2006, 07:35 PM

Tags for this Thread

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