+ Reply to Thread
Results 1 to 3 of 3

Apply Column Text as Named Range to Each Adjacent Cell

  1. #1
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Apply Column Text as Named Range to Each Adjacent Cell

    Assumptions:

    1. Column A contains text; Column B contains values
    2. User will select a gapless range within Column A and only Column A

    Upon running, I would like to apply the text of each cell within the selected range to the adjacent Column B cell as a Named Range.

    (A1 = Tom; B1 = 1,300,000; Named Range for B1 becomes "Tom"; repeat through end of selection)

    My effort below. I suppose I need help setting the selected range boundaries and likely developing the loop:

    Please Login or Register  to view this content.
    Thanks!
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Apply Column Text as Named Range to Each Adjacent Cell

    This is all you need:

    Please Login or Register  to view this content.

    Your use of "SET" should be to a range of cells, not to a numeric result like "Rows.Count" would give you. But there's no real need to set "variables" to things that are only going to be used one time after that. That's why I took out the strName variable, too, you're only using it once, so just use it directly.



    Now I have to ask why you're doing this. If you just want to be able to get the value $1,300,000 by referencing the name "Tom", a VLOOKUP formula would do that without the extra plumbing.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Apply Column Text as Named Range to Each Adjacent Cell

    Thanks so much, J. Worked perfectly.

    As to your latter question, it's for a huge mail merge and I wanted to define the names using the reference labels I created.

+ 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