+ Reply to Thread
Results 1 to 4 of 4

Global constant across whole module

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Global constant across whole module

    I have a stack of custom formulas that have grown over the years. A lot of these are year specific, so a call passes a year argument to one of the functions to pick up the correct details. In order to deal with years that aren't covered I've always started with:
    Please Login or Register  to view this content.
    clearly depending on the last year.
    The problem is when I update these I need to change that line over and over - and then sometimes forget. What I would like to do is set a global variable so I could change that to something like:
    Please Login or Register  to view this content.
    .

    I tried in the module setting Public final_year as integer and then final_year=2017 but that ain't right. How do I do it? I am sure it is simple form someone that knows more about this than me.

    Thanks in advance.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Global constant across whole module

    Hi,

    If this is a change you make manually, I'd suggest using a constant
    Please Login or Register  to view this content.
    though you could also use a cell on a worksheet or a named range to avoid having to alter the actual code each time.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Global constant across whole module

    Many thanks - worked a charm. Although threw up something I was not at all expecting elsewhere. Typical huh?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Global constant across whole module

    The law of unintended consequences.

+ 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. VBA Global Constant
    By zhbuyi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2016, 04:28 PM
  2. Global Variable in a module
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2015, 10:08 AM
  3. [SOLVED] Global Constant Password ThisWorkbook Module
    By Delvesy888 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2014, 06:14 AM
  4. Declaring Global Constant
    By anteagles20 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2012, 04:59 AM
  5. Global Variables being used in a spreadsheet module
    By ChemistB in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-04-2011, 12:37 PM
  6. Accessing Global Variables defined in ThisWorkbook Module
    By smz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2010, 08:26 PM
  7. [SOLVED] Global (Module) Variable Problem
    By Allen Geddes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2005, 11:40 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