+ Reply to Thread
Results 1 to 9 of 9

Expand named range using VBA

  1. #1
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Expand named range using VBA

    I am trying to create a macro that will add a value to an existing named range, sort the name alphabetically and then expand the named range to include the new value.

    I have managed to get the data into the list, and sort the list alphabetically. The only part I am struggling with is expanding the named range. Can anybody help?
    Here is the code so far:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Expand named range using VBA

    Hi ormerods,

    Without reading your code this looks like a job for "Dynamic Named Range" or "DNRs". They expand based on how much data there is automatically so you can write your code using the name and don't need to worry about how much data there is:

    Read up at:

    http://www.ozgrid.com/Excel/DynamicRanges.htm
    http://www.vertex42.com/ExcelArticle...ed-ranges.html
    or my favorite at:
    http://www.bettersolutions.com/excel...G820716330.htm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Expand named range using VBA

    change the code at the end of the routine
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Expand named range using VBA

    Quote Originally Posted by MarvinP View Post
    Hi ormerods,

    Without reading your code this looks like a job for "Dynamic Named Range" or "DNRs". They expand based on how much data there is automatically so you can write your code using the name and don't need to worry about how much data there is:

    Read up at:

    http://www.ozgrid.com/Excel/DynamicRanges.htm
    http://www.vertex42.com/ExcelArticle...ed-ranges.html
    or my favorite at:
    http://www.bettersolutions.com/excel...G820716330.htm
    Thanks for that, is there an issue with using this function and the INDIRECT function? I cannot seem to get it working with data validation drop down lists?

  5. #5
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Expand named range using VBA

    Quote Originally Posted by Andy Pope View Post
    change the code at the end of the routine
    Please Login or Register  to view this content.
    Thanks but this does not expand the named range it remains the same?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Expand named range using VBA

    I did not noticed the named ranges, as your original code made no reference to them.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Expand named range using VBA

    Thanks Andy I will try this on Monday. Had a read through your code and it makes no reference to the "Data" sheet where the fault is copied to, is this correct?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Expand named range using VBA

    It does implicitly by using the named range.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Expand named range using VBA

    Thanks that works perfectly

+ 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. [SOLVED] Expand named range across two separate columns
    By BlueScoob60 in forum Excel General
    Replies: 3
    Last Post: 09-04-2012, 02:50 AM
  2. cannot expand named range
    By Dreamwine59 in forum Excel General
    Replies: 1
    Last Post: 02-10-2009, 01:59 PM
  3. Cannot expand named range
    By Goatie in forum Excel General
    Replies: 1
    Last Post: 05-12-2008, 04:07 PM
  4. [SOLVED] Cannot Expand Named Range - Help
    By Snig in forum Excel General
    Replies: 5
    Last Post: 08-03-2005, 01:05 PM
  5. Replies: 1
    Last Post: 07-07-2005, 09:05 AM

Tags for this Thread

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