+ Reply to Thread
Results 1 to 4 of 4

Iteration naming range names in particular worksheets

  1. #1
    Registered User
    Join Date
    01-17-2016
    Location
    NSW, Australia
    MS-Off Ver
    Office 2010
    Posts
    2

    Iteration naming range names in particular worksheets

    G'day y'all,

    I am trying to write some code which performs the following routines:
    1. Remove any current Range Names
    2. On certain worksheets, set some range names for an unknown number of rows (ie. they will change every month)

    My code is below. For some reason, the While . . . Wend routine will only use the last used row number for the worksheet "Week 1". The Do Until, while the With . . . End loop seems to change focus to each of the 5 worksheets, seems to always stop when y= the last row of the active worksheet. So, it seems the With Worksheets() isn't changing focus to each individual sheet and I end up with the correct range names, but only based on the number of active rows in the active sheet.

    Please Login or Register  to view this content.
    Other important points:
    • Excel 2010
    • There should be no other Range Names used in the Workbook
    • I want to use the Ranges in a summary sheet in SumIF() statements


    Thank you,

    Mitchies
    Last edited by Mitchies; 01-18-2016 at 05:17 PM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Iteration naming range names in particular worksheets

    You could replace that whole routine with a dynamic named ranges, like

    Name: Week1 RefersTo: =OFFSET(Week1!$A$1, 0, 0, COUNTA(Week1!$A:$A), 1)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    01-17-2016
    Location
    NSW, Australia
    MS-Off Ver
    Office 2010
    Posts
    2

    Re: Iteration naming range names in particular worksheets

    Thanks Mickerickson,

    However, I can't get this to work - probably because I haven't worked with vba for a few years and even then, my use was not very in depth. What part of the code do I put this in? Is there a line above this code I need to insert also?

    Thanks,

    Neil

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Iteration naming range names in particular worksheets

    That's not VBA code, its a definition of a Named range.
    Go to the Name Manger and enter that formula in the RefersTo section.
    The OFFSET will start with Week1!$A$1 and will go down COUNTA(Week1!$A:A$) cells. That formulation assumes that you have no blank rows between data on that sheet.

    You just enter that definition once and then, as data is added or removed (no blank rows), the range adjusts to those changes.

+ 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. Replies: 3
    Last Post: 09-17-2014, 01:42 PM
  2. Copy Range Names To Other Worksheets In Workbook
    By The Skipper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2013, 06:06 PM
  3. How to Scan All Worksheets in a Certain Range, Compile Lists of WS names
    By justinprime in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2012, 02:09 AM
  4. Creating and naming multiple worksheets; copying contents to new worksheets
    By HeadfortheHills in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2012, 08:49 AM
  5. Iteration for sheet names
    By Dalia in forum Excel General
    Replies: 3
    Last Post: 10-28-2006, 01:03 PM
  6. [SOLVED] not delete worksheets from names in a range
    By DARREN FONG in forum Excel General
    Replies: 3
    Last Post: 11-11-2005, 01:35 PM
  7. deleting worksheets from names in a range
    By Jenn in forum Excel General
    Replies: 2
    Last Post: 08-22-2005, 07: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