+ Reply to Thread
Results 1 to 5 of 5

Naming ranges in for each loop

  1. #1
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Naming ranges in for each loop

    Hi all

    I'm trying to name single cells using the active cell column and row (splitting these and putting together) but I cannot get it to work.
    One example of the code I'm currently using:

    Please Login or Register  to view this content.
    There are 29 of these in total but I cannot get the code to set a named range.
    No errors, it just does not set a named range.

    I have also tried the following:
    Please Login or Register  to view this content.
    Any help on this is appreciated.

    Many thanks
    Last edited by Aaron092; 04-30-2015 at 07:58 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Naming ranges in for each loop

    What cells do you want to name and what do you want to name them?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Naming ranges in for each loop

    Hi Norie

    It's unknown which cells will be named, the only constant is the Columns:
    H, M, S, Z, AE, AI, AO.

    I'm getting the row to use using the following:
    Please Login or Register  to view this content.
    but then rows of data are pasted above each of these (it's a report building .. thing. I didn't ask what it was for )

    I'm trying to name the ranges as follows:

    lmone
    lmtwo
    lmthree
    lmfour
    lmfive
    lmsix
    lmseven

    saone
    satwo
    sathree
    safour
    safive
    sasix
    saseven

    colone
    coltwo
    colthree
    colfour
    colfive
    colsix
    colseven

    drone
    drtwo
    drthree
    drfour
    drfive
    drsix
    drseven

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Naming ranges in for each loop

    Sorry but I'm a bit confused.

    In the original code you posted you were looping through column C starting at row 4.

    Not sure where you are looping in the code in the 2nd post.

    Also that code isn't naming ranges and I don't see it getting row numbers either, unless you are doing something with lmcell, sacell etc.

    By the way, there is a slightly easier way to name cells.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Naming ranges in for each loop

    Norie, I am so sorry.
    The reason it's not working is because I was referencing column C only.

    It should have been C:AO
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    These do get the cell range in the loop and sets it as a named range.

    Thank you for your help - it is appreciated. Such a stupid error!

+ 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. Naming Ranges
    By j_Southern in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-13-2012, 11:07 AM
  2. naming ranges with VBA
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2005, 06:05 PM
  3. Naming Ranges
    By theillknight in forum Excel General
    Replies: 0
    Last Post: 03-11-2005, 11:38 AM
  4. [SOLVED] Naming ranges?
    By pmw5 in forum Excel General
    Replies: 2
    Last Post: 03-04-2005, 03:06 PM
  5. [SOLVED] Naming Ranges
    By Donna In Denver in forum Excel General
    Replies: 1
    Last Post: 01-28-2005, 04:06 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