+ Reply to Thread
Results 1 to 11 of 11

Userform for Selecting Open Workbooks - Copy Selections

  1. #1
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Userform for Selecting Open Workbooks - Copy Selections

    Hello Excel Masters,

    I have a userform which brings up 2 list boxes. The list boxes show all open workbooks. Here is my code:

    Please Login or Register  to view this content.

    I want to add a button to my userform which will call a macro which does the following:

    1) Copies the following range from the Listbox1 selection workbook:
    Please Login or Register  to view this content.

    2) Pastes that selection (with formatting) to the end of the Listbox2 selection workbook:

    'The worksheet name is also "Sales Details"
    The pasted values should start in the first row with no value in Column A (i achieve this by
    selecting "A9", ctrl+down

    Also, is there a way to select multiple workbooks in Listbox1 and paste the selections in each of those workbooks to the end of the Listbox2 selected workbook.

    I'm not even sure if this is possible. I have tried combining bits and pieces from other forums on ExcelForum but cant quite get something that works for me.

    Thanks,

    Brian
    Last edited by muckem333; 03-07-2011 at 04:35 PM. Reason: Added Code Tags

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

    Re: Userform for Selecting Open Workbooks - Copy Selections

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Roy,

    Thanks for the advice. This is my first time attaching a file so hopefully it works.

    I attatched 2 files, Workbook1 and Workbook2. The user would have both workbooks open. On Workbook2 (the masterfile) the user clicks the Red "Copy and Paste" button. The userform is initiated. They would select 'copy from' "Workbook1" and 'paste to' "Workbook2".

    Workbook2 is the 'after' view since it has all rows from Workbook 1 (from "A9" down) copied to the bottom of the master list.

    Although this all makes sense in my head. I'm sure there is a better way for me to explain this

    Brian
    Last edited by muckem333; 03-07-2011 at 04:42 PM.

  4. #4
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Quote Originally Posted by muckem333 View Post
    Roy,

    Thanks for the advice. This is my first time attaching a file so hopefully it works.

    I attatched 2 files, Workbook1 and Workbook2. The user would have both workbooks open. On Workbook2 (the masterfile) the user clicks the Red "Copy and Paste" button. The userform is initiated. They would select 'copy from' "Workbook1" and 'paste to' "Workbook2".

    Workbook2 is the 'after' view since it has all cells from Workbook1 copied to the bottom of the master list.

    Although this all makes sense in my head. I'm sure there is a better way for me to explain this

    Brian

    Didn't copy the files.
    Attached Files Attached Files

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

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Try adding this code to the Copy button

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Wow Roy... you ARE good! I really don't need the Listbox2. I think it just makes things more complicated because the ThisWorkbook will always be the workbook the user will be pasting to. How can I tweak the code for this?

    Also, I am getting a code execution error after everything is done pasting. When I debug, the "End With" is highlighted in the following line of code:
    Please Login or Register  to view this content.
    Last edited by royUK; 03-08-2011 at 11:46 AM.

  7. #7
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    I figured out the error. I just needed to add "Unload Me" after the "End With".

  8. #8
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Ok, I'm almost there. I deleted Listbox2 and updated the code to refer to ThisWorkbook instead of the Listbox2 value. This is what I have:

    Please Login or Register  to view this content.
    However, I am getting the same error after everything copies and pastes correctly. The debugging highlights the "End With" from the 'With Workbooks' statement.

    Any ideas how I can fix it?
    Last edited by muckem333; 03-08-2011 at 11:31 AM.

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

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Attach the new workbook

  10. #10
    Registered User
    Join Date
    12-18-2009
    Location
    Atlanta, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Roy,

    Here are the files. The button to call the process is the red "Auto Copy & Paste" Button.
    Attached Files Attached Files

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

    Re: Userform for Selecting Open Workbooks - Copy Selections

    Try this, it replaces all the code in the Userform

    Please Login or Register  to view this content.
    Note: I don't think you should include the main workbook in the list so I've changed the code to exclude it.

+ 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