+ Reply to Thread
Results 1 to 10 of 10

copy a worksheet to new workbook with filename linked to cell

  1. #1
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    copy a worksheet to new workbook with filename linked to cell

    I admit I am not good with VBA at all, but have pieced together some code from reading other forum threads. I would appreciate any help or suggestions anyone may have!!!

    I have a Command Button on Worksheet 1 of Workbook 1. When pressed, I would like for it to copy the entirety of Worksheet 2 (as values since it contains links to pivot reports) to a new Workbook (eg Workbook 2). I would like for the file name and path to be linked to user entered text in cell U11 in Worksheet 1.

    This is my code so far:

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,705

    Re: copy a worksheet to new workbook with filename linked to cell

    It would be helpful if you uploaded a sample spreadsheet with data so that we can see the entire layout of what you are attempting to copy and paste. Right now there are several compile errors in your code and it appears that you are first deleting column A and then copying column A to a new spreadsheet. So its not making much sense right now.

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: copy a worksheet to new workbook with filename linked to cell

    Thanks for the response Alan, I will get a sample sheet uploaded shortly

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

    Re: copy a worksheet to new workbook with filename linked to cell

    Give something like this a try.

    Please Login or Register  to view this content.
    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.

  5. #5
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: copy a worksheet to new workbook with filename linked to cell

    Okay, I've uploaded a mock-up of my workbook. (I think I did this properly, let me know if you cannot access the file). I've also outlined my goals for the end product below.

    1.) The user selects various parameters via slicers on "GUI" sheet. Number of cells/columns in "Worksheet 1" are dynamic based on user selection.
    2.) The user enters pathname and filename into cell U11 on "GUI" sheet.
    2.) Entirety of Worksheet 1 is copied and pasted into new workbook with path name and file name equal to entered value in cell "GUI" sheet, cell "U11"

    Thanks so much in advance for your time and help!

    Excel Forum Sample Doc.xlsm

  6. #6
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: copy a worksheet to new workbook with filename linked to cell

    Thanks for all of your help AlphaFrog!

    I just tried out your code substituting appropriate worksheet names and I am getting a "Run-time error '1004' PasteSpecial method of Range class failed" error at the line ".PasteSpecial x1PasteColumnWidths." Do you have any insight as to why this may be happening?

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

    Re: copy a worksheet to new workbook with filename linked to cell

    Did you change the L to a 1 ?
    x1PasteColumnWidths

    Should be...
    xlPasteColumnWidths

    Otherwise, show your modified code.

  8. #8
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: copy a worksheet to new workbook with filename linked to cell

    Hi again,

    Yes, the l's are now 1's

    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,652

    Re: copy a worksheet to new workbook with filename linked to cell

    No. They should be Ls and not ones.

    The original code I had posted has Ls which is correct.

    You stated it errored...
    Quote Originally Posted by pika View Post
    ... error at the line ".PasteSpecial x1PasteColumnWidths." Do you have any insight as to why this may be happening?
    ... and quoted it with a one which is incorrect. I was asking if you had incorrectly inserted a one where it should be an L.
    Last edited by AlphaFrog; 10-21-2013 at 05:59 PM.

  10. #10
    Registered User
    Join Date
    10-21-2013
    Location
    cambridge, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: copy a worksheet to new workbook with filename linked to cell

    I transcribed it incorrectly when I was modifying the code...the secondary workbook is saving properly now.

    Thank you so much for all of your help AlphaFrog!!!

+ 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. Copy slection and paste it in ceratian workbook with PART filename as cell value
    By Dibbley247 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-15-2012, 09:56 AM
  2. Replies: 0
    Last Post: 11-01-2012, 09:28 AM
  3. [SOLVED] To rename a workbook filename with the column value of a worksheet.
    By Vinutha in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-18-2012, 04:29 AM
  4. Copy Worksheet Without Filename In Linked Formulas?
    By Kncuda in forum Excel General
    Replies: 0
    Last Post: 12-20-2010, 04:18 PM
  5. VBA code: save worksheet as separate workbook; use cell values as filename
    By ACurtis802 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-17-2009, 07:23 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