+ Reply to Thread
Results 1 to 7 of 7

LastRow and Multiple Ranges

  1. #1
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    LastRow and Multiple Ranges

    I am using the following line of code in a bunch of different spreadsheets.

    Please Login or Register  to view this content.
    The current whole code I am using it in is as follows:

    Please Login or Register  to view this content.
    What I tried to do was the following:

    Please Login or Register  to view this content.
    The above did not work.

    Since the main code is copying from one sheet to another, I was hoping that either the code i changed would work and if not how do I code the second copy/paste command to the book created by the Workbook.Add line. K1:L would need to be pasted into H:L on in the "existing" new book.

    I could also edit the existing code to just delete the rows I don't need but i was curious to know if multiple ranges could be selected
    Last edited by dagindi; 05-21-2010 at 09:22 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: LastRow and Multiple Ranges

    Did you try without a macro? I get the following: The command cannot be used on multiple selections.
    You can't copy non-continuous selections. You'd need to instead use:

    Please Login or Register  to view this content.
    Or, if easier, you could just copy the entire sheet into a new workbook and delete everything you don't need off of it. See Worksheets().Copy
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: LastRow and Multiple Ranges

    Like so:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: LastRow and Multiple Ranges

    Hmm, thought I tried that but must've got something wrong. Thanks for the correction JB.

  5. #5
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: LastRow and Multiple Ranges

    Deleting original post in response to davegugg.
    Last edited by dagindi; 05-17-2010 at 06:04 PM. Reason: Updated code from JBeaucaire that I need to try.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: LastRow and Multiple Ranges

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  7. #7
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: LastRow and Multiple Ranges

    Finally got a chance to run this and it worked perfectly!!

    Many thanks to both of you!

+ 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