+ Reply to Thread
Results 1 to 4 of 4

Using Named Ranges for a loop statement

  1. #1
    Forum Contributor
    Join Date
    11-21-2017
    Location
    USA
    MS-Off Ver
    2016
    Posts
    150

    Smile Using Named Ranges for a loop statement

    I created a mini search engine. The routine allows the user to input data in cell B3 on the "List" tab so that when he/she hits the search button a list of matches generate. The list of matches are based on column A of the "Data" tab.

    While the code works just fine, the problem I am having is using named ranges. I would like to reference the named ranges in my code instead of using regular column/row syntax.

    If you open up my excel spreadsheet you will see my attempts to change the syntax to named ranges indicated by the comments just so you can compare the code that works to the code that doesn't.

    I only have three named ranges which are all part of the data tab. Column A is "NM" (where it searches for the match), Column B is "DESC", and Column C is "NM_DESC".

    I can't seem to make it work when it comes to the loop statement. I've tried several different ways and it always comes up as an error. Any help would be appreciated!
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Using Named Ranges for a loop statement

    For Each x in [NM] makes x a range (loops through each cell in the named range) not a number which is why your for loop would error out.

    So instead of Cells(x,1) and so on, you'd have to use x.Row: Cells(x.Row,1)

    This loop seems to work:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 04-24-2018 at 01:39 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    11-21-2017
    Location
    USA
    MS-Off Ver
    2016
    Posts
    150

    Re: Using Named Ranges for a loop statement

    That did the trick, Arkadi. Thank you very much.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Using Named Ranges for a loop statement

    Happy to help

+ 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. Loop Defining Named Ranges
    By lopiner in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-20-2017, 02:57 PM
  2. Add named ranges via loop
    By aBc894543 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2016, 11:04 AM
  3. [SOLVED] Loop through columns and named ranges
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 06-02-2015, 12:14 PM
  4. How to combine named ranges into IF statement
    By frsaxon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-01-2015, 02:46 PM
  5. Multiple Named Ranges Pasting Loop issue
    By pacman_d in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-13-2010, 09:46 PM
  6. named ranges in a For Loop
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2005, 11:10 AM
  7. Using named ranges in AdvacendFilter statement
    By Laurence Lombard in forum Excel General
    Replies: 1
    Last Post: 05-15-2005, 09: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