Excel Tips Tutorial: How to Enter Credit Card Numbers In Excel
Excel Tips Tutorial: How To Make Gantt Chart in Microsoft Excel
Excel Tips Tutorial: Pivot Tables
Excel For Noobs Tutorial: How to use IF function for logical calculation
Excel For Noobs Tutorial: How to use data filtering in MS Excel
Excel Tips Tutorial: How to Use Concatenate Function to Join Cells Together
Excel For Noobs Tutorial: How to create graphs in Excel
Excel Tips Tutorial: How to Insert Cells in Data Tables in MS ExceI
Excel Tips Tutorial: How to Convert Values From One Measurement System to Another
Excel Tips Tutorial: How to Convert Numbers to Text
Excel Tips For Noobs: How To Add Diagonal or Crossed Lines to a Cell
Excel Tips Tutorials: How to Make A Pie Chart in Microsoft Excel
Excel Tips: How to Solve Circularity Errors With Iterations
Excel Tips Tutorial: How To Use Vlookup in Microsoft Excel
Excel Tips Tutorial: How to use SUMIF, COUNTIF and AVERAGEIF Functions in Microsoft Excel
Excel Tips Tutorial: How to Use Conditional Format in Microsoft Excel
Excel Tips Tutorial: How to Connect Links to Excel Worksheets
Excel Tips Tutorial: How To Write Formulas In Excel
Excel Tips Tutorial: How to Find and Replace Values in Microsoft Excel
Excel Tips Tutorial: VBA Visual Basic for Application For Beginners in Microsoft Excel
Excel Tips Tutorial: How to Use Trim, Upper, Lower and Proper In Microsoft Excel
Excel Tips Tutorial: How to Convert a PDF File to Editable Excel File
Excel Tips Tutorial: How to Use Pivot Tables in Microsoft Excel
Excel Tips Tutorial: How to Find and Select Content or Cells in Excel
Excel Tips Tutorial: How to Merge Styles and Themes of Old and New Excel Versions 2003 2007 2010 2013
Excel Tips Tutorial: Microsoft Excel Keyboard Shortcuts
Excel Tips Tutorial: How to Draw a Line Through a Word in Excel - Strikethrough
Excel Tips Tutorial: Horizontal Text Alignment in Excel (General, Left, Center, Right, Fill, Justify, Center across Selection and Distributed)
Excel Tips Tutorial: Vertical Alignment in Excel (Top, Center, Bottom, Justify, and Distributed)
Excel Tips Tutorial: How to Display Text at a 45 Degree Angle (Diagonal Text)
Excel Tips Tutorial: How to add a Background Image (Picture) to an Excel Worksheet
Excel Tips Tutorial: How to Use Format Painter to Copy and Paste Cell Formats
Excel Tips Tutorial: How to Use Cell Styles to Format Cells
Excel Tips Tutorial: How to Change the Default Style of an Entire Excel Workbook Using Cell Styles
Excel Tips Tutorial: How to Create Your Own New Cell Style in Excel
Excel Tips Tutorial: Understanding and Applying Themes in Excel
Excel Tips Tutorial: How to Pin Important Excel File to the Recent Files List
Excel Tips Tutorial: How to Add Folders to the Favorites List in the Open Dialog Box
Excel Tips Tutorial: How to Save Excel Workbook Files
Excel Tips Tutorial: How to Change the Default File Type to Save Excel Workbooks
Excel Tips Tutorial: How to Open and Recover an Unsaved Excel File
Excel Tips Tutorial: Rules for Filenames in Microsoft Excel
Excel Tips Tutorial: How to Print Only an Excel Chart without Printing out the Entire Worksheet
Excel Tips Tutorial: How to Remove Formula Error-Checking Smart Tags
Excel Tips Tutorial: How to Stop Automatically Creating Calculated Columns in Excel Tables
How to Name an Excel Table
Excel 2013 Tutorial: How to Refer to a Named Cell as a Constant
Excel Concatenate Function Tutorial - How to Join Text in Excel
How to Use If Else If Function in Excel 2013 - Nested If Function in Microsoft Excel
Excel Worksheets Tutorial for Microsoft Excel 2013
Absolute, Relative and Mixed Cell Reference Excel Tutorial
Excel 2013 Tutorial Creating and Opening Workbooks in Excel 2013
Excel 2013 Tutorial The Function Library
How to Share Workbooks in Excel 2013 Tutorial
Save and Save As Excel 2013 Tutorial
How to Recover Unsaved Files in Excel 2013 with the Auto Saved Feature
How to Export Excel Files to PDF Other Different File Types
Basic Excel 2013 Functions Tutorial
Excel Tutorial How to Use Nested Functions
How to Use GoTo Special in Microsoft Excel 2013 Tutorial
Excel Page Layout Tutorial
Microsoft Excel Tutorial Page Breaks, Headers and Footers
Excel 2013 Tutorial How to Format Fonts in Excel
How to Create a Custom List in Excel Tutorial
Data Validation Microsoft Excel 2013 Tutorial - How to Restrict Entering Data in a Cell
Understanding Excel Charts Tutorial
How to Create a Basic Chart in Excel Step by Step Tutorial
How to Create and Use a Pivot Table in Microsoft Excel 2013 - Excel Pivot Table Tutorial
How to Pivot Data with Excel Pivot Tables Tutorial
How to Create a Macro in Microsoft Excel 2013
Microsoft Excel 2013 Worksheet Template Tutorial How to Create
Drop Down Lists Tutorial in Excel 2013
How to Reference Formulas and Data on other Excel Worksheets Worksheets Microsoft Excel 2013 Tutorial
Excel Data Forms Tutorial Microsoft Excel 2013
How to Insert Drawing Objects into your Excel Spreadsheets Microsoft Excel 2013 Tutorial
Excel LOOKUP Function Tutorial Microsoft Excel 2013
Excel Workbook and Worksheet Objects Tutorial
Excel Tutorial: Variables in Microsoft Excel Visual Basic Application (VBA)
Excel VBA Tutorial: If Then and Else Statement in Microsoft Excel (VBA) Visual Basic Application
Excel Events Tutorial: Visual Basic Application Evens in Microsoft Excel 2013
Excel Tutorial: Variables in Microsoft Excel Visual Basic Application (VBA)
In this lesson we will learn about variables in excel VBA and how to they work. We will see how to declare, initialize and display a variable. If we declare a variable it means we are letting Excel VBA know that you are using a variable. If we assign a beginning value to that variable it is Initializing.
Variable can be of multiple types few basic types are below.
Int, String, Double and Boolean.
Now we will see how to declare each type of variable and how to use them.
- Open your excel book and create a command button, if you don’t know how to create a command button, you have to see our tutorial on how to create macros.
- Now open visual basic editor by clicking on Visual Basic Button in Developer Tab.
- How to Declare and initialize Integer, add the lines of code below.
Dim x As Integer
x = 6
Range("A1").Value = x
- Click on Command Button to see results
- The code is performing some actions, in first line Dim x As Integer, it is creating a new variable named “x” and in second line it is assigning a value “6” to variable x. in third line value of “x” is being added to cell A1.
- To Declare and initialize a String, add following lines to code.
Dim book As String
book = "bible"
Range("A1").Value = book
- On first line a String type variable has been created and on 2nd line variable is assigned by a value “bible”, on third line value of variable “book” is displayed in cell “A1”.
- Value of Double type variable is more accurate than integer, and it can also store values after decimal point. To declare and initialize double type of variable do write the following lines of code.
Dim x As Double
x = 5.5
MsgBox "value is " & x
- In above lines of code, value of x is displayed in a message box. First a variable of type double is declared, after that value “5.5” is assigned to variable x. in last step value of “x” is displayed in message box along with a string “value is”.
- Same as to declare a Boolean variable add the following lines
Dim continue As Boolean
continue = True
If continue = True Then MsgBox "Boolean variables are cool"
- “Continue” is a Boolean type variable declared in first line, and assigned as “true” in second line. In third line an “if” condition is applied, if “continue” is equal to “True” then Display “Boolean variables are cool” in message box.
- You can assign either True or False to a Boolean variable.