+ Reply to Thread
Results 1 to 7 of 7

Selecting range question

  1. #1
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Selecting range question

    There's a ton of examples of how to find the last row with data out there, and I'm sure there's a simple solution I'm just not getting, but here's my dilemma:

    In column "A" I need to select the 2nd row, find the last row with data in column A, then move over to column "E", which may or may not have data in it.
    So the range I need to copy will always extend A to E, but to number of rows will be determined by the last row with data in column A.

    Have attached simple spreadsheet if that helps.

    thanks
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Selecting range question

    Try this...

    Range("A2", Range("A" & Rows.Count).End(xlUp)).Resize(, 5).Copy

  3. #3
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Selecting range question

    Perfect - thanks!

  4. #4
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Selecting range question

    as a follow-up to this question, I'm trying to copy that range into another workbook using the following code:

    Please Login or Register  to view this content.
    Is there anything wrong with this? It seems most examples i've found are declaring variables and the code to copy from one workbook to another is about 3 times as long. Is that necessary here?

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Selecting range question

    You should specify the workbook and worksheet for referencing the last used cell in column A
    Please Login or Register  to view this content.

    or just use a With-End With code block.
    Please Login or Register  to view this content.
    And use an Exit Sub to prevent displaying the MsgBox when there is no error.

  6. #6
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Selecting range question

    Thanks again - tried both and both resulted in a "subscript out of range" error.

  7. #7
    Registered User
    Join Date
    06-15-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Selecting range question

    it worked perfect. The sheet name had a space at the end of it I was unaware of.

    thanks again!

+ 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