+ Reply to Thread
Results 1 to 3 of 3

VBA code to amend named range

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    VBA code to amend named range

    Hi All,

    Sure this will be a simple query but I can't get my code to work. I'm not great at coding (self taught) but can find my own way normally by recording and Googling! I have a named range ("SalesPeople") that I want to alter once a new sales person is added to the data. My code is currently thus:-

    ActiveWorkbook.Names("Salespeople").Refers to R1C1 = "=DATA!R1C5:R8C5

    Effectively my current list of sales people populate E1:E8 on the DATA worksheet. My macro currently makes a number of changes to the workbook to incorporate this new salesperson however I need the above code to change the named range to incorporate the new salesperson whose name is sat in E9. I want the code to essentially rename the range to E1: end of selection ie, E9. Next time a new sales person starts the range would rename to E1:E10 etc etc. Not sure if I need to count the number of cells or maybe use some form of Selection.End(xlDown)?

    The named range is used for Data Validation when assigning a sale to the relevant sales person by the way.

    Any help that could be afforded to me would be most appreciated!

    Regards
    Paul

    ** EDIT - Forgot to mention file is currently 5MB so I can't post to the thread unfortunately! **
    Last edited by pdean52; 04-01-2015 at 12:46 PM. Reason: Forgot to mention cant attach file.....!!

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: VBA code to amend named range

    You can use the offset formula in the named range instead of VBA to create a named range that dynamically grows or shrinks as needed.

    http://www.excel-easy.com/examples/d...med-range.html
    http://www.contextures.com/xlNames01.html


    but if you want to keep the VBA:
    Please Login or Register  to view this content.
    or more complete:
    Please Login or Register  to view this content.
    Last edited by mikeTRON; 04-01-2015 at 01:06 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA code to amend named range

    Perfect! Thanks mikeTRON - I hadn't even considered the fact I could use the offset formula in the named range! Much easier than going down the coding route so thank you very much....!!

    Paul

+ 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. Amend code to do nothing if cells in a range are empty
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2015, 07:38 AM
  2. How to amend coding for Data Validation refer to a Named Range?
    By montroseite in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2010, 09:35 AM
  3. Using a named range in VBA code
    By TripleC in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-26-2010, 04:41 PM
  4. Amend code to change range from Col D to a Range
    By Redd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2009, 05:34 PM
  5. Macro code to change cell range to named range
    By Orlic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2008, 11:51 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