+ Reply to Thread
Results 1 to 7 of 7

macro to create named ranges based on a header row.

  1. #1
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    macro to create named ranges based on a header row.

    hello, I need a macro that can set up some named ranges using the text in the header row and the sheet name. The header row will always be in row one, but the number of columns will be dynamic. The amount of rows in the range will need to be dynamic also. To clarify, every used cell stating in row 2 in a column will be the named range with the sheetname+text in row one of the column the actual name.

    Thanks!
    Clayton
    Last edited by dcgrove; 10-16-2009 at 10:02 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro to create named ranges based on a header row.

    Hello Clayton,

    This will create named ranges based on the column headers and rows used in each column. It can be run later if there are any changes to ranges and the named ranges will be updated.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: macro to create named ranges based on a header row.

    Leith, the macro is failing to this error:

    \1


    On this line:

    Please Login or Register  to view this content.
    Any ideas why? I have uploaded the test sheet I tried it out on.

    I am running the code from my personal.xlsb workbook.

    Thanks!
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro to create named ranges based on a header row.

    Hello Clayton,

    Problem was that a named range has to start with either a letter or underscore character. So, I switched the order around. The Header appears first then then worksheet name. I used periods instead of underscores to replace the spaces in the worksheet name. The header and worksheet are separated by an underscore. The change has been made to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: macro to create named ranges based on a header row.

    Leith, this worked great!

    Thanks!

  6. #6
    Registered User
    Join Date
    08-07-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: macro to create named ranges based on a header row.

    This is very helpful thread. However, looking at the example file, all the ranges have quotations marks (" ") around them. For example one range refers to "09 28 2009'!$I$2". Do you know how I can change the code to get rid of the quotation marks?

    Thanks for your help.

  7. #7
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: macro to create named ranges based on a header row.

    Hello tetreama, and welcome to the forum.

    Unfortunately you have inadvertently broken one of the forum rules. Please read the following and make the necessary change. Thanks.

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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