+ Reply to Thread
Results 1 to 7 of 7

How to use named ranges in VBA?

  1. #1
    Registered User
    Join Date
    03-24-2024
    Location
    staines uk
    MS-Off Ver
    2000
    Posts
    2

    How to use named ranges in VBA?

    Suppose you have a table that looks like this:

    Fruit Apples Oranges etc

    John (numbers)

    Bill

    Sue

    etc



    and you insert > name > create the names in the top row & L column,
    then in a formula you can say things like

    = John Apples

    or

    = Apples + Oranges

    Meaning the values in that row. Please is there any way to do the equivalent
    in VBA? If (in VBA) you have option explicit and you say

    x = John( 2)

    you get an undefined variable error.

    Sorry if this is a FAQ. I searched. Only thing I could find that looks relevant
    was is 2006 . Somebody said " use the INDEX function" but I didnt
    say how to do this. INDEX requires numerical arguments, so it cannot use
    the defined names .

    Thank you.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: How to use named ranges in VBA?

    Fast answers need clear examples.

    See yellow banner at top of the page on how to attach a workbook.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: How to use named ranges in VBA?

    If you have a range named 'John', you can refer to in in VBA as
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-24-2024
    Location
    staines uk
    MS-Off Ver
    2000
    Posts
    2

    Re: How to use named ranges in VBA?

    thank you for replies. I tried to attach a file.
    In it I created the names in row 1 & col A & in col G are some formulae that
    refer to cells in these ranges.
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: How to use named ranges in VBA?

    This will give you the number of apples for John:
    Please Login or Register  to view this content.
    and this will give apples and pears
    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: How to use named ranges in VBA?

    Some examples:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: How to use named ranges in VBA?

    And with mgs73's suggestions added:

    Please Login or Register  to view this content.

+ 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. Copy values of all named range in wb1 to identically named ranges in wb2
    By JAMIAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2016, 06:58 PM
  2. [SOLVED] VBA creates named ranges, but named ranges disappear
    By BrotherNeptune in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2015, 03:22 PM
  3. Define only 2 named ranges from a list of named ranges...
    By abhi900 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-29-2014, 04:20 AM
  4. Looping Mutliple Named Resized Ranges in next empty row below another named range
    By gingumdog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2014, 08:15 PM
  5. [SOLVED] Determining if the value of a cell can be a named range, then assigning named ranges after
    By Romulo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2013, 06:05 PM
  6. Copy data in named ranges to a newer version of the same template to identical ranges
    By handstand in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2006, 10:51 AM
  7. Replies: 1
    Last Post: 03-21-2006, 06:40 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