+ Reply to Thread
Results 1 to 20 of 20

Getting Path from FilePicker so as to copy and paste a sheet

  1. #1
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Getting Path from FilePicker so as to copy and paste a sheet

    Hi,

    I think this is a fairly simple question, but I'm still new at this and so I don't know the answer. I have the below I'm using to enable the user to choose a file from a dialog box:

    Please Login or Register  to view this content.
    I'd like to take columns A:AW of the "Test" sheet on the workbook selected by the user and paste it into "This Workbook" same sheet and range. I'm attempting this using the below:

    Please Login or Register  to view this content.
    That clearly doesn't work. Is the problem here that while the user has chosen the portfolio, "SourcePortfolio", the user has actually NOT chosen the exact path, so my Workbooks code above is not working. If that's the case, can someone please advise how I can fix it?

    Thanks!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Perfect! Thank you.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    You are very welcome.

  5. #5
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    I'm sorry, but I have one additional question.

    The sheet that I'm working with is effectively relies on a dynamic matrix whereby the columns and rows can change. So, as you can see, the first part of this process is taking a sheet that is holding said dynamic matrix and pasting it elsewhere. When I call up the code it seems that row 1 pastes accordingly. But if, for example, the dimensions of the matrix change, the remaining rows after 1 don't seem to adjust (the heading in column C might move correctly to column D but the remaining rows in column C DO NOT move to the appropriate portion of column D).

    Any idea why that might be happening? Thanks again!

  6. #6
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    in fact, i'm wondering if it would be more effective/efficient to simply copy all cells on the sheet instead of that specific range...

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Try replacing this line of code:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Ok that's much closer and actually, as I'm testing it, will probably work in 99% of cases. That said, it seems like because of the way UsedRange works, I do have one example sheet that isn't being copied correctly. What's the easiest way to choose all cells on the sheet and copy them (effectively the button above row 1 to the left of column A). Even though the above code works in almost all of my cases, I think simply copying and pasting all the cells might ensure that the code will always work.

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    This code
    Please Login or Register  to view this content.
    should copy all the cells. What is the difference between the one sheet where the data isn't being copied correctly and the other sheets?

  10. #10
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    it's mainly a function of column width. Typically most of the ranges i'm dealing with are A-AI (I'm mainly using a subset of this, but still the entire matrix width covers that range). Yet, the main difference in the one that acts a bit strange is that the range covers A-BD. So the range is much larger, but based on the code I'm not sure why that would matter.

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    "UsedRange" sometimes doesn't act as expected. Can you attach a file with a copy of the sheet that is giving you problems?

  12. #12
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Sure. Keep in mind the numbers no longer make sense because they're all randomly generated to preserve confidentiality. But you can see this version has many more columns than the original used in the test case and for some reason I notice that the header (row 1) seems to copy over but nothing else does so everything becomes misaligned...

  13. #13
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Attachment...
    Attached Files Attached Files

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    If you run this test macro:
    Please Login or Register  to view this content.
    and check the sheet, you will notice that the entire used range has been copied correctly so I don't see why it is giving you a problem.

  15. #15
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Ok, not sure what the problem was, but it seems like it was on my end. I think it all works now. Thank you so much!

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    My pleasure.

  17. #17
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Sorry to open this up again, but I think I found my issue (sort of).

    I've attached an example of output after just this copy code was run. The paste should end in row 614, but as you can see part of the top half of the sheet was pasted below in the bottom half (see row 552). The bottom half, however, isn't even pasting directly; rather the paste almost seems in some ways almost random. Is this mistaken paste on the bottom somehow related to "UsedRange"?

    Thanks again.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    it looks like I need to insert ClearContents prior to the paste

  19. #19
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    Yup, got it. Thanks again

  20. #20
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,834

    Re: Getting Path from FilePicker so as to copy and paste a sheet

    My pleasure.

+ 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. Sheet copy to path in row problem
    By martinus1988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2016, 04:48 PM
  2. Replies: 1
    Last Post: 02-27-2014, 01:28 AM
  3. Copy Range from Excel and Paste it in MS Word and then save it in a specified path
    By prasadcherry in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2012, 02:29 PM
  4. Formulas contain PATH info after copy/paste
    By JWM6 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2011, 12:59 PM
  5. Pass path result from FilePicker to vlookup with correct syntax
    By sabs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-10-2005, 06:44 PM
  6. Copy and Paste Formula Without the linked file path
    By KevinB in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2005, 07:06 PM
  7. Replies: 1
    Last Post: 01-04-2005, 06:06 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