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

Excel 2007, 2010에서 개발도구 보이게 설정하는 방법
How to set developer tools visible in Excel 2007, 2010

▼ How to set the developer tools to be visible in Excel 2013 or later

Excel 2013 이후 버전에서 개발도구 보이게 설정하는 방법
How to set development 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.

VBE(Visual Basic Editor) 화면
Visual Basic Editor (VBE) screen

Here, click “View menu > Immediate Window”.

직접 실행 창 메뉴 클릭
Click on the Immediate window menu

The Immediate window is displayed as follows.

직접 실행 창 표시
Show the Immediate Window

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.

"Hello, World!" 메시지 출력
“Hello, World!” message output

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.

직접 실행 창에서 cell에 값 입력
Enter values into cells in the Immediate window

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.

파일 새로 만들기 결과
File New Results

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 >>

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish