+ Reply to Thread
Results 1 to 18 of 18

need to copy sheet to another workbook

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    need to copy sheet to another workbook

    i need to copy a worksheet to another workbook. the problem is that i dont know what that workbook will be until i run my macro. so need a macro to ask the user to point to an excel workbook, then copy the worksheet over.

    i know how to create a worksheet but not how to copy it to the other workbook (in VBA).

    can someone help?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Quote Originally Posted by dmcgov View Post
    so need a macro to ask the user to point to an excel workbook, then copy the worksheet over.
    Can you better explain "point to an excel workbook"? Do you want...
    A.) a file picker dialog so the user can select an Excel file to open?
    or
    B.) a dialog with a list of already opened Excel files?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    12-07-2015
    Location
    Kedah, Malaysia
    MS-Off Ver
    2007
    Posts
    8

    Red face Re: need to copy sheet to another workbook

    Hye Alpha,

    I also have the same problem here. For example we have File A and File B. Inside File A, the Price is located in column C while in File B the Price is located in column F. The File A we can call it as the master File. So the Price data in File B want to be copy exactly in File A but located inside column C. Hope you can help.

    Thank you.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Quote Originally Posted by Fidi1202 View Post
    Hye Alpha,

    I also have the same problem here. For example we have File A and File B. Inside File A, the Price is located in column C while in File B the Price is located in column F. The File A we can call it as the master File. So the Price data in File B want to be copy exactly in File A but located inside column C. Hope you can help.

    Thank you.
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

  5. #5
    Registered User
    Join Date
    12-07-2015
    Location
    Kedah, Malaysia
    MS-Off Ver
    2007
    Posts
    8

    Talking Re: need to copy sheet to another workbook

    Okay noted.

    Im sorry. Will post a new thread regarding my question.

    Thank you.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Quote Originally Posted by Fidi1202 View Post
    Okay noted.

    Im sorry. Will post a new thread regarding my question.

    Thank you.
    Thank you for understanding.

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    Quote Originally Posted by AlphaFrog View Post
    Can you better explain "point to an excel workbook"? Do you want...
    A.) a file picker dialog so the user can select an Excel file to open?
    or
    B.) a dialog with a list of already opened Excel files?
    I would pick A, a file picker dialog box

    thanks

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    so below is the code that i am using. it doesnt work though, it fails on this line: Sheets("formulas").Copy Before:=Workbooks(FileName).Sheets("a")

    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Try this. ThisWorkbook is the workbook with the macro.

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    when i run it, i get a "run time error '9': subscript out of range.

    what do you think is wrong with this macro?

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Quote Originally Posted by dmcgov View Post
    when i run it, i get a "run time error '9': subscript out of range.

    what do you think is wrong with this macro?
    You haven't explained very well which workbook you want to copy from and which workbook you want to copy to.

    ThisWorkbook.Sheets("formulas").Copy Before:=Workbooks(FileName).Sheets("a")
    This copies a sheet called "formulas" located in the workbook that contains the macro code and pastes it in the newly opened workbook after a sheet called "a". For all I know, that could be backwards from what you really intend.

    The error is because one of the two workbooks does not exist, or one of the two named worksheets doesn't exist. I suspect it's one of the named sheets isn't in it's qualified workbook.

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    ok so the workbook that has the macros in it, is named "estimate test"
    the workbook that it is going to (for testing purposes) is called "102 angler with macros" but this is the one that will change based on the end user picking a file to put the sheet "formulas" into. this needs to be dynamic. and 102 angler has the sheet "a" in it.

    as for "estimate test", this will always be that name.

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Quote Originally Posted by dmcgov View Post
    ok so the workbook that has the macros in it, is named "estimate test"
    the workbook that it is going to (for testing purposes) is called "102 angler with macros" but this is the one that will change based on the end user picking a file to put the sheet "formulas" into. this needs to be dynamic. and 102 angler has the sheet "a" in it.

    as for "estimate test", this will always be that name.
    Does "estimate test" have a sheet named exactly "formulas" and does "102 angler with macros" have a sheet named exactly "a" ?

    If yes, then give this a try.
    ThisWorkbook.Sheets("formulas").Copy Before:=ActiveWorkbook.Sheets("a")
    Last edited by AlphaFrog; 12-08-2015 at 12:36 PM.

  14. #14
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    Yes, I just checked both workbooks. estimate test has "formulas" and 102 angler has "a".

  15. #15
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    i can upload both files if needed

  16. #16
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    Give this a try.
    ThisWorkbook.Sheets("formulas").Copy Before:=ActiveWorkbook.Sheets("a")

  17. #17
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: need to copy sheet to another workbook

    Quote Originally Posted by AlphaFrog View Post
    Does "estimate test" have a sheet named exactly "formulas" and does "102 angler with macros" have a sheet named exactly "a" ?

    If yes, then give this a try.
    ThisWorkbook.Sheets("formulas").Copy Before:=ActiveWorkbook.Sheets("a")
    i tried that and it works!!! thanks so much

  18. #18
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: need to copy sheet to another workbook

    You're welcome.

+ 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. [SOLVED] macro to copy rows from a sheet in one workbook to a sheet in a different workbook...
    By fredderf81 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-16-2013, 01:36 PM
  2. Simple Open Workbook, Copy Sheet, Paste In New Workbook Question
    By alulla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2013, 02:10 PM
  3. Replies: 0
    Last Post: 04-26-2013, 03:40 AM
  4. [SOLVED] Copy Values From Each Workbook in Folder to a Single Sheet in New Workbook +Workbook names
    By Arsham24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2012, 07:42 PM
  5. Macro, copy UNLOCKED cell range of sheet in open workbook to workbook template
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-31-2012, 11:18 AM
  6. [SOLVED] Copy All Sheets From Each Workbook in Folder to a Single Sheet in New Workbook
    By DHartwig35805 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-21-2012, 03:53 PM
  7. [SOLVED] copy active sheet, create new workbook, name new workbook based on cell reference
    By jm0392 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2012, 07:12 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