+ Reply to Thread
Results 1 to 4 of 4

Refering to column with a "given name" in VBA

  1. #1
    Registered User
    Join Date
    01-18-2019
    Location
    France
    MS-Off Ver
    365
    Posts
    2

    Refering to column with a "given name" in VBA

    Dear All

    First I wish you a happy new year 2019.

    My problem:
    I made macro which is relating to a thousand of lines and columns and this macro is quiet heavy (But very useful !).
    In the following months I will have to add and remove columns without to affect my macro.
    My problem is that rewrite all my formulas by changing old column names to new column names is to much time consuming.

    My question :
    Is it possible to give to a column a "given name" (i.e. "climbing") like a constant?
    "Given names" of column would be given in respective cells along the first line of the sheet.

    Then in the formula of my macro I could refer to the given name of a specific column (i.e. =SUM("climbing")) instead of initial column names (i.e."'=SUM(D:D)).

    Therefore, my macro will not be affected by adding or removing column (Except if I give the same name to different columns)


    Thanks for your answer.

    Théo

  2. #2
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: Refering to column with a "given name" in VBA

    Yes, you can name cells and ranges in Excel. Highlight your range, then select the address bar (above the worksheet and to the left of the formula bar; it will normally contain the address of the active cell. Overwrite that with your range name.

    For instance if you want A1:A100 to be named "Climbing", highlight that range, then select the address bar and enter Climbing into it and hit enter. Now, it you select your formula tab and select the Name Manager, you will see that the named range exists.

    From VBA, you can refer to this range as Range("Climbing").

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: Refering to column with a "given name" in VBA

    I may have 2 tidbits of assistance: If you Name your ranges, using TOP Row( Under: Formulas/ Create from Selection /Top Row) it will allow you to use the Named Range for each column. If you use this with making your data a TABLE (Home/ Format as table), you will have the benefits of a Table. Specifically, if you Add rows or Delete rows - your named range will adjust automatically! Words of Wisdom from my late mom: "Take a chance...Columbus did!"
    Please add reputation if this helps you.

  4. #4
    Registered User
    Join Date
    01-18-2019
    Location
    France
    MS-Off Ver
    365
    Posts
    2

    Re: Refering to column with a "given name" in VBA

    Thanks a lot for your answer !

    Still have to fully implement it in my project but it seems to solved my problem !

    Have a good day,

+ 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. Replies: 5
    Last Post: 11-29-2017, 11:05 PM
  2. Replies: 6
    Last Post: 07-16-2017, 09:06 AM
  3. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  4. Replies: 1
    Last Post: 08-20-2016, 01:59 AM
  5. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  6. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  7. [SOLVED] "criteria" in a sumif refering to the value in another cell
    By mark in forum Excel General
    Replies: 1
    Last Post: 01-31-2005, 04:06 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