+ Reply to Thread
Results 1 to 9 of 9

Run-time error '5' when copying range of cells to different sheet

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Leverett, MA, USA
    MS-Off Ver
    2010
    Posts
    5

    Run-time error '5' when copying range of cells to different sheet

    Hey everyone - first post here, so be gentle.

    I've got two sheets, the source which is a inventory list - column H is the amounts of line items being used, and the requisition list which is supposed to collect those line items that have been used (i.e. have a value in column H). I've tried doing this with the following code but get a run-time error when I step through past the Range(Cells(... line.

    Anything stand out...? Thanks in advance for any help.

    M

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Run-time error '5' when copying range of cells to different sheet

    Hi, Meriwether,

    Please Login or Register  to view this content.
    is causing the run-time error as Cells expects the range either as a numeric (Cells(1) stands for the first cell in the range) or by row number and column number / character (Cells(1, 1) and Cells(1, "A") refer to Range("A1")). You try to use a string with multiple entires as a reference to range. And you would not need to Select a range prior to copying it.

    If you could point out which cells you want to copy over I´m sure we may help you with that code as well if you need help on it.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Leverett, MA, USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Run-time error '5' when copying range of cells to different sheet

    Thanks Holger! Man, this chat really is fast. What people say is true!

    The code needs to loop through all line items in Sheet1 (~1300 of them) and for the ones with a value in column H (i.e, where Quantities have been filled in) I'd like the corresponding cells in columns A, C, E, H, & N for each line item to copy over to Sheet2.

    Really, the only cell I need copied is the item name for each line item in column H. All others I could do through a simple in-cell VLOOKUP with the name as reference. Although, learning how to put it all into a Macro would be cool.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Run-time error '5' when copying range of cells to different sheet

    Hi, Meriwether,

    if you want to copy only Column H:
    Please Login or Register  to view this content.
    for more columns you may take an approach like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    Leverett, MA, USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Run-time error '5' when copying range of cells to different sheet

    Thanks Holger -

    I can't seem to get either of these to work. For the copying of only column H I'm almost getting it. Only problem was my mistake: the correct cell to be copied should have been from column E... The value is copied correctly, but it is from the wrong cell. I've tried to figure out how to use your code and specify the correct cell but can't figure it out.

    The second code you posted does something, but I don't know what. It seems that formulas get copied... I'm probably not giving you enough or correct info. I don't know what half of the formulas you use in this one are, so I'm going to have to spend a bit more time on that before I have something of value to say.

    Can I share screenshots with you, or the file itself? Feels like I've got a whole lot of stuff going on here that I'm not communicating: columns A, C, and D in sheet2 are dropdown lists linked to a master inventory list, and some of the cells I'm interested in copying have formulas in them.

    Vielen dank.
    Carl

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Run-time error '5' when copying range of cells to different sheet

    Hi, Meriwether,

    either
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    should work for Column E.

    You should make clear if you want formulas and formats copied over or just the values of the cells.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    06-26-2014
    Location
    Leverett, MA, USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Run-time error '5' when copying range of cells to different sheet

    Thanks again man... It works, although I can't figure out how to copy only values over...

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Run-time error '5' when copying range of cells to different sheet

    Hi, Meriwether,

    Please Login or Register  to view this content.
    will copy formulas and formats,
    Please Login or Register  to view this content.
    will copy the value.

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    06-26-2014
    Location
    Leverett, MA, USA
    MS-Off Ver
    2010
    Posts
    5

    Re: Run-time error '5' when copying range of cells to different sheet

    Terrific! Oddly enough, the code seems to pull line items without values in the H column as well as the ones with values... I tried clearing the column using clear contents, but once I did that the code stopped working altogether.

    In the pic, some of the items in the 4th column from the left has quantities, but not others. I don't want to copy over ones that don't have a quantity. That's also going to clear up the #VALUE! errors.

    Excel1.JPG


    ED: I figured it out. Apparently, I couldn't clear contents on the entire column. Had to clear the buggers out one by one. Thank you Holger - this excel inventory list is working beautifully now.
    Last edited by Meriwether; 06-27-2014 at 03:02 PM.

+ 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. #REF Error When Copying A Sheet In A Sum Range
    By centerNegative in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-02-2013, 11:21 PM
  2. Copying Data error from master sheet based on Range criteria
    By naga in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2013, 02:11 AM
  3. Copying Sheet - subscript out of range error
    By GSP@DCS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2006, 09:00 PM
  4. [SOLVED] Run time error '4605' while copying excel range as picture in Wor
    By Samirkc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2006, 10:50 AM
  5. Replies: 3
    Last Post: 07-24-2006, 08:20 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