+ Reply to Thread
Results 1 to 9 of 9

Opening file, copy and paste range

  1. #1
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Opening file, copy and paste range

    Hello everyone,
    I'm sure this is a very basic question, but I'm new at this. I'm trying to prompt the user to select an Excel workbook, then copy and paste a range of cells from that workbook into the active one. This is my attempt below:
    Please Login or Register  to view this content.
    The dialog box successfully opens, and the selected file successfully opens, and then I get a run-time error 91 on the following line:
    Please Login or Register  to view this content.
    Again, this is probably something really stupid but all the same I need help. Thanks!
    Last edited by alansidman; 05-28-2019 at 08:14 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Opening file, copy and paste range

    I know my eyesight is not what it used to be, but I could swear that the line you are having a problem with is not in the procedure you posted. BTW, this forum requires that you use code tags when you post macros or parts of macros. You can edit your original post, select the code portion of the post and click the pound (#) symbol to apply the code tags. It will keep the moderator from scolding you. Is there a different code that you meant to post that contains the problem line?
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Opening file, copy and paste range

    This line
    Please Login or Register  to view this content.
    isn't in the code you posted.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Opening file, copy and paste range

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    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

  5. #5
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: Opening file, copy and paste range

    Sorry about all of that! I was in a hurry last night. I did in fact post an error line from the wrong program. I have read the rules and will be sure to follow them from now on.

    Good news is, I've gotten closer to my goal. I made a new program, and I'm having a new problem, but it's very much a related problem so I think I'll keep it in this same thread.

    The code below is meant to copy data ranges from two different user-selected spreadsheets (wbThis an wbThat) and paste them into two different tabs of wbTarget. It is mostly working, it is prompting the user to select both workbooks, but when it's done, wbTarget has data from wbThat on both tabs, instead of wbThis on one tab and wbThat on the other. WbThis seems to be getting overwritten. Does anyone know why that might be?

    Please Login or Register  to view this content.
    Last edited by Feethurt; 05-29-2019 at 11:26 AM.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Opening file, copy and paste range

    Please Login or Register  to view this content.
    The above statement is the reason it is overwriting. The code is telling it to paste data from This and That to the same range. If you want to avoid that, assuming that column A will be as lengthy with data as any of the other columns then for the That workbook data you can use:
    Please Login or Register  to view this content.
    Which should put the data From workbook That under the previously pasted data.

  7. #7
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: Opening file, copy and paste range

    Thanks for the tip, but that doesn't seem to be the problem. "H28_F116 CW Data" and "H28_F116 CCW Data" are two separate sheets within the same workbook. I can't see any reason that anything should be getting overwritten.


    I want to put two datasets from two different user-selected files on two different sheets within the same "target" workbook: In cells A10:BG5233 of sheet "H28_F116 CW Data", and A10:BG5233 of sheet "H28_F116 CCW Data".

    Thanks for all the help so far. Does anyone see what the problem might be?

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Opening file, copy and paste range

    Didn't see a problem with your code except the pastespecial statement, so I modified it a bit. See if it works...
    Please Login or Register  to view this content.
    Last edited by dangelor; 06-03-2019 at 01:47 PM.

  9. #9
    Registered User
    Join Date
    05-28-2019
    Location
    Indianapolis
    MS-Off Ver
    Excel 2016
    Posts
    12

    Re: Opening file, copy and paste range

    Dangelor, thank you for the suggestion. What I ended up doing was programming wbThis and wbThat to close once I was done with them, and that fixed the problem. I may try your suggestion though.

    I'm now having a new problem: I'm trying to paste data to the first empty row in a spreadsheet. Despite lots of resources addressing this common and seemingly simple task, I can't come up with code that works. I'm going to start a new thread as that problem doesn't really match this title.

+ 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] Copy range and paste in a new excel file.
    By Vagelisr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2018, 07:31 AM
  2. Copy Visible Range in Excel and Paste into Text File
    By jpv5 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-14-2016, 09:15 AM
  3. [SOLVED] Copy same range in many excel files and paste into a main file
    By dualaudio454252 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-15-2014, 05:25 PM
  4. macro to copy used range and paste in the body tag of a html file/text file
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 08:34 PM
  5. Macro required for copy a range, create a new txt file and paste it
    By gm2612 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-28-2013, 07:25 AM
  6. Code to copy range from 200 + workbooks and paste into one csv import file
    By CharlieMappley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2013, 10:41 AM
  7. Copy and paste without opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-20-2010, 10:14 AM

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