Excel VBA Course (2): Excel VBA Basics
2. Excel VBA Basics
2.1. Basic Preferences
To use VBA-related functions, first set the Developer tab to be visible on the Excel ribbon menu. Depending on the Excel version, the displayed screen is slightly different, but the method is almost the same.
Run Excel and go through the following steps to set it up.
File > Options > Customize Ribbon > Check “Development Tools” > OK > Check Show “Development Tools” in Ribbon
▼ How to set the developer tools to be visible in Excel 2007, 2010
▼ How to set the developer tools to be visible in Excel 2013 or later
This completes the basic environment setup.
2.2. Follow simple example
Before getting into the theory, let's follow a simple example using Excel VBA.
2.2.1. “Hello, World!” output
Let's print “Hello, World!”, the first example (😉) of any development language.
Click the “Visual Basic” button in the developer tool ribbon menu or use the shortcut key Alt + F11 If you press , VBE (Visual Basic Editor) appears as follows.
Here, click “View menu > Immediate Window”.
The Immediate window is displayed as follows.
Copy and paste the following code into the Immediate window and press Enter.
MsgBox "Hello, World!"
Hello, World!” A message window appears. Close it by clicking the “OK” button.
2.2.2. Entering values into cells
This time, let's look at the code to enter a value in a specific cell of the sheet. Copy and paste the following code into the Immediate window and press Enter.
Range("B2") = "직접 실행 창에서 입력"
You can confirm that the specified value is entered in the “B2” cell as follows.
2.2.3. New file
Let's create a new file this time.
Workbooks.Add
A new “Workbook 3” is created. The number is the number of new files incremented by 1 after Excel is launched. The number may be different for each execution environment.
I've followed environment settings and simple examples so far. If you are new to Excel VBA, please give it a try.
Next, we will take a look at the Excel Object Model.
<< Related article list >>
- Start the Excel VBA course. (Lecture notice, feat. Why we recommend Excel VBA)
- Excel VBA Course(1): Overview of Excel VBA
- Excel VBA Course (2): Excel VBA Basics
- Excel VBA Course (3): Excel Object Model
- Excel VBA Course (4): Working with Excel Object Model
- Excel VBA Course (5): Excel File Extension, VBE, Font Settings
- Excel VBA Course (6): Excel VBA Language Basics - Variables
- Excel VBA Course (7): Excel VBA Language Basics - Syntax
- Excel VBA Course (8): Excel VBA Language Basics - Data Types, Data Structures
- Excel VBA Courses (9): Excel VBA How-To
- Excel VBA Course (10): Tools developed and used with Excel VBA
- Full Table of Contents for Excel VBA Courses