How to assign a value to a variable in Excel

A variable is an identifier that you provide, for example, a security or a sum of money. The input values ​​in the Excel spreadsheet can use the same variables you created. You need to understand how this works so that you can assign values ​​to these variables and perform calculations with them.

You can refer to the article “How to assign a value to a cell in Excel” to learn more about the basics of variables and cells in Excel. This article will explain how to assign a value to a variable and perform calculations with it.

Using variables in the spreadsheet

You can use variables in your spreadsheet in a couple of ways. One way is that you can assign them values ​​directly from another cell.

  • For example, you can create a variable called “payment” and then assign it the value which is in A2.

This means that if the value in A2 changes, the value in payment will change.

  • If you want to access the value of a variable from another part of the spreadsheet, you can use the REFERENCE command. The small fx icon at the top right of the formula bar allows you to insert a cell reference or variable within a formula.
  • If you click the fx icon and type a variable name in the box that appears.

When you click on the variable in Excel, you will see all the values ​​that have been assigned. Your formula can use this information elsewhere.

Creating variables

To create variables in your spreadsheet, you must

  • Use the “Define name” option from “To insert” option on your “Developer” form.
  • You can make the default “Developer” tab visible by going to yours “File” menu and clicking on “Options”.
  • There, click on the box that says “Show developer tab in ribbon”.
  • This will extract the Developer tab.
  • Now, go to yours “Developer” tab and choose “Define name” from its “Insert” submenu. A dialog called “New name.”.
  • In the box for a new name, enter the name of your variable.
  • In the box labeled Scope, choose whether you want this variable to be a local variable or a global variable.

Local variables can only be used in the worksheet where you created them while global variables can be used in any worksheet within the workbook that contains them.

  • Now, in the box labeled Refers To, you need to tell Excel which cell you want to assign a value to.
  • If you want this variable to refer to another cell, type the address pointing to that cell. If you want this variable to refer to another variable, type the name of that other variable. Now, scroll down and click “OK”.

You can now use your new variable in your formula just as if it were a normal value or reference.

How to name variables in Excel

Within an Excel formula, an equal sign is followed by a variable name. However, if you want to make this variable available for use in other formulas, you must create a name for it. This means assigning the variable to a cell with its name. You should also include the equal sign with the cell name when creating. This way, Excel will always use this specific cell as a reference in calculations where that variable is involved in some way.

Here are some examples of how to name variables in Excel:

  • * A1 + B1 + C1 + D1 = SUM (B2: B4) * This formula will add the values ​​B2 to B4 to those already contained in cell A1.
  • *A2:=SUM(B3)*This formula calculates the sum of the values ​​contained in cells B3 through B9. When the above formula is entered into cell A2, Excel will calculate all cells contained in columns B3 to B9, starting from row 2 and going to row 10.
  • *A2*=B2*This formula multiplies the value in cell B2 by the value in cell A2. It then calculates the results contained in column A, starting with row 2.

Once you enter a variable name into an Excel spreadsheet and save it, you can use it as often as needed.

Excel spreadsheet

Excel variable list

There are three types of variables that you can use in your spreadsheets. Are the following:

  • User defined variables
  • User-defined constants
  • Global or globalized variables

All are accessed in the same way by clicking on the drop-down menu relating to the type of variable. Different names you can use as long as it’s not already used in the document.

variable type

Excel variables in a cell reference

The second way to use variables in Excel is to write an equal sign before the variable name. The equal sign is followed by a cell reference that finds the value of a specific cell.

Variables are not case sensitive, so you can use uppercase or lowercase letters when using them. You can have variables with numbers and letters, but they must be enclosed in single or double quotes. Single quotes are usually used with one or two letters in the variable. Double quotes can be used for variables that include more than two letters.

  • Using a colon separate multiple variable names and their cell references in the same formula. For example, the formula “=SUM(x:x)” means to add the values ​​of the variables x and x. Of course, you can also use your variable in a formula without cell references.
  • In your formula, you can just type the variable name. For example, typing “=x+y” will add values ​​to variables x and y as long as they were previously written to separate cells of an Excel spreadsheet.

By using two different variables in one formula, the formula will be more complicated.

  • For example, suppose we have the variables x and y and we want to calculate their sum.

You can use the equal sign to separate both of these values. However, it’s probably easier to just type “=SUM(y)” as Excel will automatically figure out that y is a function of x.

  • This also means that you can use single quotes for variables that contain only one or two letters. Variables in the range of cells.

The third way to use variables in Excel is to create a range of cells. A cell range occurs when you put the names of two or more cells together, separated by colons.

  • The formula “=SUM(A2:A3)” sums all cells in column A that are in the specified range in A2 and A3. Of course, you can also use multiple variables and cell ranges in the same formula. This allows you to calculate more than one variable at a time.
  • For example, the formula used in the previous example could be changed to: “=SUM(B2:B4)”
  • This means that the sum function will use the values ​​B2 to B4 to calculate the total of these variables. Column and row cells can be contained in a range of cells.

Excel declares a variable in a formula

Excel 2016 introduced the ability to declare variables in formulas. This allows you to define a variable and then use it in formulas without the need to list its name as part of the formula.

  • To do this, press “Alt” + “F2” or click “Formula” icon at the top left of Excel and select “Define a new variable”.
  • To redefine an existing variable, select that variable from the list of available variables and enter a name for it in step 2.
  • The far right option allows you to create a variable in the function editor. To do this, enter the name of your variable in the “Function Arguments” box. You can also define which cell will be used for each variable if it is not already specified for use.
  • To declare a single variable, click “Single Variable (x)”. You will be able to specify a value for x in your formula. Type your value in the box below.
  • Use “Multiple variables (x1, x2, x3, etc.) ”To declare several variables in a formula. You should separate each variable with a comma after typing its name. This will tell Excel which cells to use for each variable.

  • Use “Unique Expression” if you want your formula to be inserted into a single cell without requiring cell references as part of its function. You must type the entire formula, including any function variables and arguments, into the box below.
  • If you want your formula to enter multiple cells, or if you want your formula to enter a specific range of cells, click “Multiple cells (x1:y1; x2:y2; x3:y3; etc.)” or “Range A1:B1”. You should separate each cell reference with a comma.
  • Use “Multiple range” if you want to create a formula that works with multiple ranges. You should separate each range with a comma and enclose the entire range, including the brackets, in parentheses.


How to assign a value to a variable in VBA?

If you want to assign a value to a variable in VBA, you need to do it with one of these three methods:

1. Use “Update” and then use the notation that corresponds to the variable.
2. Use “Write” followed by your variable name.
3. Use “Set” followed by the name of your variable.

How to assign a word a value in Excel

If you want to assign a word value to a variable in Excel, use it first “Find and Replace” to change the value of the word. Then, use the formatting option that corresponds to assigning a value to your variable.

How to assign a number to a value in Excel

To assign a number to a variable, use the formatting option that matches numbers.

Final word

Most Excel users take advantage of the ability to use variables to perform complex calculations without having to rewrite them over and over again. This is especially true when using formulas that reference more than one cell since you can enter a formula once and use it in many different cells.

When your formulas include ranges that match variables, this can save you even more time in the long run. Using variables also makes it easier to repeat calculations.

If the data in your spreadsheet changes, you can simply change the value of a variable and all formulas using that variable will automatically update. This means that updating a large spreadsheet takes much less time and can take much less time overall.

Leave a Comment