+ Reply to Thread
Results 1 to 8 of 8

Copy/paste vba script results in missing data or method of range class failed

  1. #1
    Registered User
    Join Date
    07-02-2012
    Location
    614
    MS-Off Ver
    Excel 2010
    Posts
    43

    Copy/paste vba script results in missing data or method of range class failed

    Tried umpteen different ways to get this to work and only two do (sort of, but not really), and ultimately result in errors.

    The first routine copies and then if any data exists on the worksheet, it should then be copied to a second worksheet -- problem is, when it copies to the second worksheet, the first way (without errors) there is no data, only highlights the same number of cells in the range on the second sheet. The second way, when I run an activeworksheet.paste (or a couple of other ways -- I've spent so long looking at it I'm seeing sideways), it results in method of range class failed, but throws the error AND copies the data.

    I'm almost sure it's something simple and could use a fresh set of eyes... What am I missing? Or is there an easier way?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by numbnuts; 07-02-2012 at 11:35 AM.

  2. #2
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Copy/paste vba script results in missing data or method of range class failed

    I'm not quite sure what you are doing at the end, cleaning up the Label History blank rows?

    I've put applicable code names on your worksheets, to make it a bit clearer which worksheet you are working with. I moved the LabelPrint .ClearContents back into the main code, it really didn't need to be part of the range selection function.

    Anyway, take a peak at the code, let me know what you think.

    Book1.xlsm

  3. #3
    Registered User
    Join Date
    07-02-2012
    Location
    614
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Copy/paste vba script results in missing data or method of range class failed

    Thaks for your reply, wallyeye...

    Indeed, I was trying to clean up any blank rows. After I ran your script and it wiped out my data, I commented out that part of the routine and the copy paste worked -- Not sure why it was deleting everything since there's data in those cells. The userinput will maybe eventually be selectable by mouse once I move on past this copy problem (though to keep it simple, it might just be easier to select the starting row and ending row of the range which is why I added that bit), and to avoid any blank row copies (I was trying to think ahead) I appended that little portion to the code, which I've used it in the past (there's probably better ways to accomplish that, I'm sure, but previously it did what it was supposed to) -- in this case, exactly the opposite of the desired effect. The data on the merge sheet may or may not always be populated and the cell ranges can and likely will contain blank rows, so in selecting 1:30, blanks will likely exist on both pages being pasted to.

    Can you suggest a way to avoid copying blank rows?

    My original intent was to concatenate on demand (you can observe the columns/delimiters in the formula of the merge sheet), but that proved to be too taxing at the moment and outside of my skill set.

    Thanks, again, for your assist!

  4. #4
    Registered User
    Join Date
    07-02-2012
    Location
    614
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Copy/paste vba script results in missing data or method of range class failed

    Seriously -- I've been working on the details of this for about a week now, trying to find the best way to approach this problem and the few minutes you spent put me on the right track and I can finally start moving forward and fleshing this out. You.Are.Awesome.

    I did, by the way, find a better way to approach the line deletion, by just shifting some of the code around. So again, thank you.

    Please Login or Register  to view this content.
    Last edited by numbnuts; 07-02-2012 at 08:33 PM.

  5. #5
    Registered User
    Join Date
    07-02-2012
    Location
    614
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Copy/paste vba script results in missing data or method of range class failed

    Also, having not known the actual name of the standard, 'Hungarian Notation', until today and prior to your first reply, seeing you had changed my sheet labels to match was a nice reminder that it's just good practice, personal or otherwise, to maintain it's use in one's code. I'll try to remember, in the future when uploading my workbooks, to maintain that sort of notation across all aspects of my code/work.
    Last edited by numbnuts; 07-03-2012 at 12:10 AM.

  6. #6
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Copy/paste vba script results in missing data or method of range class failed

    I use my version of Hungarian quite extensively, it certainly helps with keeping variables and objects straight in my head when reading code.

    Glad to be of assistance!

  7. #7
    Registered User
    Join Date
    07-02-2012
    Location
    614
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Copy/paste vba script results in missing data or method of range class failed

    I guess my next question, given the changes to the code, what would be the best way to approach error handling with the 'selusrrng' inputbox? I can't seem to lock down an exit sub on pressing cancel... I've tried both in the function and in the selusrrng call in the main sub and I still wind up getting kicked to 424 "Object Required".

    Here's my changes so far (see comments within the code for locations):

    Please Login or Register  to view this content.
    Had I not just spent the last few days, off and on, banging my head against a silly worksheet specific button in RibbonX I'd be more inclined to try further, but my head hurts and I'm exhausted...

    Any thoughts?
    Last edited by numbnuts; 07-06-2012 at 11:44 PM.

  8. #8
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Copy/paste vba script results in missing data or method of range class failed

    I was hoping to find a Dialog box for selecting a range, but can only find an Inputbox. The input box doesn't handle cancel quite as well, so you will need some error trapping, and I would recommend bringing it into your main module:

    Please Login or Register  to view this content.

+ 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