+ Reply to Thread
Results 1 to 5 of 5

The meaning of the word "Variable"

  1. #1
    Registered User
    Join Date
    11-17-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    69

    The meaning of the word "Variable"

    Hello,

    As part of my understanding about the terms VBA uses, I have been trying to understand where the word "Variable" comes from. I just copied this from a website:

    "After assigning a value to a variable, you can use that variable knowing the value it is currently holding. At any time and when necessary, you can change the value held by a variable. That's why it is called a variable (because its value can vary or change). To change the value held by a variable, access the variable again and assign it the new desired value."

    So, just to be clear in my mind, the value of a variable will not change unless you initiate that change? For example, if you wrote a piece of VBA code and assigned a value to a variable, then that variable will not change unless you go back to the code and change the variable value?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: The meaning of the word "Variable"

    A simple variable is just the name of a storage location.

    Please Login or Register  to view this content.
    Depending on the type of variable, VBA limits the nature and range of data it can contain.
    Last edited by shg; 04-01-2015 at 08:17 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-17-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: The meaning of the word "Variable"

    Thanks shg, so is the last question in my post correct? That is what I am trying to get my head around that's all.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: The meaning of the word "Variable"

    Hey Steve,

    In general you are correct. The variable won't change value after you assign it a value unless you change it. There are other parts to this question. A variable is created in a Subroutine in the VBA code using the DIM statement. When the Subroutine ends all the variables created in it are removed from the memory of the computer. Sometimes this is called "tossed off the stack". A way around this is to declare the Variable as Global so it lives longer than the life of the subroutine.

    This site might explain it better:
    http://analysistabs.com/excel-vba/scope-of-variables/ or this one http://www.cpearson.com/excel/Scope.aspx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: The meaning of the word "Variable"

    You might find the glossary in vba help useful.

    Variable

    A named storage location that can contain data that can be modified during program execution. Each variable has a name that uniquely identifies it within its scope. A data type can be specified or not.

    Variable names must begin with an alphabetic character, must be unique within the same scope, can't be longer than 255 characters, and can't contain an embedded period or type-declaration character.
    Cheers
    Andy
    www.andypope.info

+ 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. [SOLVED] (Challenge) Sum Order From Count "Center" Word To Start Word & "Center" Word To End Word
    By sanju2323 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2015, 12:58 AM
  2. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  3. [SOLVED] Removing ".", "?" or "!" from last word of sentence and replacing it later in vba.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2013, 07:20 AM
  4. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  5. use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 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