+ Reply to Thread
Results 1 to 8 of 8

Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

  1. #1
    Registered User
    Join Date
    05-24-2016
    Location
    Tampa, Florida
    MS-Off Ver
    2016
    Posts
    14

    Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Hey Guys. I am trying to write a code that copies a specific range of cells from one worksheet (called Game) into another worksheet's (called Games 1-500) next available row. Here is the code I have thus far:

    Please Login or Register  to view this content.
    I am getting Error 9 "Subscript out of range" -- I have read that this could be from Excel trying to execute a code from a worksheet which does not exist. I have verified that the two sheets named in the code are in the fact correct so I'm not sure why I'm still getting this error. Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Have you checked there are no leading/trailing/errant spaces in the worksheet names?
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Hi Brad,

    The code working fine for me.


    Please Login or Register  to view this content.
    1. Thank those who have helped you by clicking the Star * below the post.
    2. Please mark your post [SOLVED] if it has been answered satisfactorily.

    Sincerely,
    Farid

  4. #4
    Registered User
    Join Date
    05-24-2016
    Location
    Tampa, Florida
    MS-Off Ver
    2016
    Posts
    14

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Thanks for the responses. Norie may have been correct, there may have been a space somewhere in code because I copied the above code and it worked. The problem is the macro copies the contents into the wrong cells. I have attached the workbook so you guys can see what I am working with. The first part of the macro is fine, it copies the worksheet "Game" cells H3:O3 (I originally had I3 but fixed that). It pastes into the worksheet called "Games 1-500" but copies to cell C512 (which technically is the next row with nothing in it) but I want it to paste to Range C33:J33 (the next open line) and so on. What do I need to add to my code to tell Excel to do that? Thanks for the help!
    Attached Files Attached Files

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Where do you actually want to copy the data to?

    I can see why it's being copied to row 512 but that can be fixed by using column B to find the next empty row instead of A.

    However, which column(s) should the 7 values from I3:O3 be pasted to?

    Is it column F?

    Also, is there other data that needs to be copied/put into columns in the same row as I3:O3 is being copied to?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Just saw your updated post and I think it's column C that needs to be used to find the next empty row.

    That's what this code does.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-24-2016
    Location
    Tampa, Florida
    MS-Off Ver
    2016
    Posts
    14

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    Quote Originally Posted by Norie View Post
    Just saw your updated post and I think it's column C that needs to be used to find the next empty row.

    That's what this code does.
    Please Login or Register  to view this content.
    This worked perfectly, thank you. Just for my personal benefit: I noticed the "wsGame1500.Cells(Rows.Count, 3) changed from (Rows, Count 1) -- I'm assuming the 1 equals column A (thus 3 equals C). Having said that, I still don't see where Excel reads the code that tells it to place the values under each line of game stats instead of starting at row 512?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy One Range of Cells in One Worksheet to Next Available Row in Another Workbook

    This will return the next empty cell in column C(3).
    Please Login or Register  to view this content.
    Cells(Rows.Count, 3).End(xlUp) is just like going right to the bottom of column C and pressing END followed by the up arrow, ie it takes us to the last piece of data in the column.

    We then offset 1 row to get the next empty cell in the column.

+ 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. Replies: 0
    Last Post: 07-24-2014, 09:11 AM
  2. Iteratively copy cells from one worksheet in a workbook to another worksheet in another wo
    By amandeepsharma89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-23-2014, 01:58 PM
  3. [SOLVED] Copy range to new workbook w/some cells as values & some cells as formulas in new workbook
    By happydayze in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2013, 12:42 PM
  4. Copy text from set range in one worksheet to named worksheet in another workbook
    By Steven811 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2013, 10:55 AM
  5. [SOLVED] Copy certain cells before save from a worksheet in one workbook to a worksheet in another
    By Marianne Rachmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2012, 07:16 PM
  6. copy range from active worksheet to another workbook
    By omarq in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-03-2011, 06:21 PM
  7. Copy Range of One Worksheet Into Another Workbook
    By HP RodNuclear in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2010, 11:56 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