+ Reply to Thread
Results 1 to 8 of 8

Inputboxes to select range to copy and range to paste from different workbooks

  1. #1
    Registered User
    Join Date
    11-14-2013
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Inputboxes to select range to copy and range to paste from different workbooks

    Hi,

    I'm writing a macro that will allow users to import data into a sheet. The way I've set it up I'm wanting to lock the sheet down so that the only way end users can update the values is through following the process I've set out in the macro. Generally the data will be coming from a standardised summary template from a different workbook (which I've gotten to work), but I've been trying to build in a back door that will allow the user to manually select where this data comes from and where to manually paste it using inputboxes (incase something gets changed in the future it means they'll still be able to use the import function without the macro breaking). This is the part I'm struggling with. For some reason it keeps failing at this particular line (which I've also highlighted red in the macro below):
    Please Login or Register  to view this content.
    I've used similar code in other macros (in the same workbook even) and can't seem to get my head around why it keeps failing here...I'm sure it's something simple and I'm overlooking it because I've been looking at this macro for too long. If someone is able to help out I'd be greatly appreciative.

    My macro is as follows:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    Seems confusing, at least to me, that namesheet2 relates to wb and namesheet relates to wb2. You should be consistent in your naming. Whatever, try without the wb. and the wb2.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-14-2013
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    Quote Originally Posted by TMS View Post
    Seems confusing, at least to me, that namesheet2 relates to wb and namesheet relates to wb2. You should be consistent in your naming. Whatever, try without the wb. and the wb2.

    Regards, TMS
    Thanks for the reply Trevor, apologies, I usually do keep my naming consistent...it just got a little out of whack while I was trying different things.

    If I run it without the wb. and the wb2. then I get Run-time error '1004': Method 'Range of object'_Worksheet' failed, which makes sense given the two ranges are in different workbooks so it can't find them if it's looking for them both in the same workbook...if I'm understanding this correctly? Yet if I reference the workbooks as in my original posted code (i.e. running it with the wb and wb2) I get Run-time error '438': Object doesn't support this property or method.

    Please see updated code below with consistent naming:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,336

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    Sorry, on holiday so we've been out walking the walls round Dubrovnik.

    You use Set UserRange, hence UserRange is a range object. But then you use it in Range(UserRange) where UserRange is expected to be a string variable with a range address.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    11-14-2013
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    No worries, I really appreciate you taking the time to reply while on holidays! The walls round Dubrovnik must be a site to see.

    Ok, that makes sense. What would you feel is the best way to achieve what I'm after in this situation? Would it work if I used Dim UserRange As String and kept everything else the same (I'm not at work at the moment to check)? Or would it be a case of converting UserRange to a string before using it to call the cell values?

    I've tried setting UserRange as a range object and then having namesheet.UserRange.Value but this doesn't work either.
    Last edited by graphicgoose; 06-29-2014 at 09:54 AM.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    namesheet is a range variable, assigned to a worksheet in wb2.
    namesheet is not a property of the workbook wb2
    Therefore the code wb2.namesheet will cause an error.

    There is no need to qualify wb2.
    Similarly UserRange and UserRange2 are range objects (not cell addresses). They are already specific to wb2 and wb.

    Try replacing the red code (in the OP) with

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Registered User
    Join Date
    11-14-2013
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    Thanks Mike, that all makes sense. I'll give your suggestion a go when I get to work in the morning. As you can tell, I'm still fairly new to VBA. It's such a powerful tool though, and i really enjoy learning and using it...It has a certain creativity element to it that appeals to me.
    Last edited by graphicgoose; 06-29-2014 at 10:17 AM.

  8. #8
    Registered User
    Join Date
    11-14-2013
    Location
    Perth, Western Australia
    MS-Off Ver
    Excel 2016
    Posts
    49

    Re: Inputboxes to select range to copy and range to paste from different workbooks

    Thanks so much mikerickson, that worked a treat. I can't believe it was that simple!

+ 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. Need dynamic range select and copy Paste
    By rags_rags in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2013, 03:49 PM
  2. Select Range, Copy, Paste, FAIL! :p
    By prefix in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2009, 03:46 AM
  3. Variable to select range to copy and paste to
    By cecil23 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-30-2007, 02:35 AM
  4. [SOLVED] Copy same range of data from all workbooks and paste into consolid
    By JEFF in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-18-2005, 04:06 PM
  5. [SOLVED] Copy/paste range variable between workbooks
    By Jim73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2005, 05:06 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