+ Reply to Thread
Results 1 to 4 of 4

Help with Non Contiguous Row Ranges

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Help with Non Contiguous Row Ranges

    Hi All,

    I've got the following code in use:

    BookLastrow = Range("A3").End(xlDown).Row
    DVDLastrow = Range("A739").End(xlDown).Row
    
    'More Code yadayadayada
    
    Set ALLISBN = Range("A3:A & BookLastrow, A739:A & DVDLastrow")
    However I am getting a run time error 1004. Basically to cut a long story short I'm trying to future proof the macro so when people insert rows into the workbook the macro will handle it without me hard coding the different absolute references.

    The absolute cell references as they are at the current time are:

    Set ALL ISBN Range("A3:A736, A739:A1023")
    I can get

    Set ALLISBN = Range("A3:A & BookLastrow, A739:A & DVDLastrow")
    to work only if I add speech marks to for example:

    ("A3:A" & Booklastrow, "A739:A" & DVDLastrow)
    However the above also gives the cells inbetween e.g. A736 to A739 when I run the code through (which is not what I want). It's hopefully just a syntax thing if anyone can help?

    Thanks

    Chriz
    Last edited by Chriz; 07-25-2013 at 06:27 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Help with Non Contiguous Row Ranges

    BookLastRow is going to return the same as DVDLastrow... i.e. the last row of data in column A... You'll have to find another method to determine the last row of book data
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Help with Non Contiguous Row Ranges

    I have addressed similar issues by using named ranges. For instance, if you name A3:A736 as RANGE1, then any rows inserted will be part of the range. So if someone adds 3 rows at row 4, RANGE1 will now refer to A3:A739. Just reference the range name in your macro instread of the absolute address.

    Note that is someone tries to append a row (say row 737) to the range, this will not be part of the named range, because row 737 is not part of RANGE1.

    Hope that helps.

  4. #4
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Help with Non Contiguous Row Ranges

    Ok many thanks both for your replies. I'm going to give the Named ranges a go, sounds like an ideal solution and will mark this as solved.

+ 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. Contiguous "Range" from Non Contiguous Ranges
    By DonkeyOte in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-03-2011, 03:23 PM
  2. Copy and Paste an array (contiguous & non contiguous ranges)
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2010, 09:17 AM
  3. Sorting Non Contiguous Ranges
    By tekman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2009, 04:58 PM
  4. [SOLVED] vlookup on non-contiguous ranges
    By BorisS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-15-2006, 05:35 AM
  5. sorting non contiguous ranges
    By gsh20 in forum Excel General
    Replies: 1
    Last Post: 09-08-2005, 12:05 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