VBA basics
6. Let's write it anyway (Sub, End Sub)

Excel macro basics and applications, introduction to Excel VBA
last updated:08-14-2019

6. Let's write it anyway (Sub, End Sub)

Some of this topic was processed by machine translation. Original


Let's write a macro anyway.


macro vba range

sub practice1

And enter

macro vba range

In this way, sub becomes Sub, and () follows.
And End Sub is added below.

This is a macro.
It becomes a macro with one function.


Various processing contents are written between Sub and End Sub.
In the above, no function is written, so only the macro container is prepared.


When you write something in Sub, write it down one step, which is called indentation.

To do so, press the "TAB" key.
The "TAB" key is the third from the top left of the keyboard (on most PC).

macro vba range

In this way, by pressing the “TAB” key, the character will be lowered (shifted to the right) by 4 single-byte characters.

Let's add a little bit.


Before that, let me explain the future,
The description part of the macro is displayed in a frame as shown below.
This is to make it easier to distinguish from other explanatory text on the displayed page.

Sub practice1()
  Range("A1") = "Hello!"
End Sub


This is a macro that puts the words "Good morning!" In the cell in column A, row 1 of the worksheet.


When typing, use lowercase letters.

macro vba range

You can continue to input before and after =.
And when you enter,

macro vba range

in this way,
range is Range, and the first character is converted to upper case.
This means that Range is the correct description and has been converted automatically.
However, if the spelling is wrong and renge is entered, it will not be converted to upper case.
Therefore, when typing, enter it in lowercase letters.
This has the problem of typing and has the advantage of making it easier to notice misspellings.

However, double quotes are not converted because they are fixed characters.
Even if "a1" is entered, "A1" is not converted.
Since A1 is a cell address,
It is recommended to put it in capital letters so that it looks the same as the function on the sheet.

In addition, before and after =, half-width blanks are automatically formed and are easy to see.
There is no need to enter single-byte spaces before and after =.
Of course, there is no problem even if you enter single-byte spaces before and after =.



Articles with the same theme "VBA basics"

3. Macro recording
4. Where is the macro written (VBE startup)
5. VBE Set Options (Option Explicit)
6. Let's write it anyway (Sub, End Sub)
7. To run a macro (F5)
8. What is putting a character in a cell (Range, Value)
9. How to specify cells in Range
10. Specification method other than Range (Cells, Rows, Columns)
11. How to use Range and Cells
12. Variables and data types (Dim)
13. Constants and type declaration characters (Const)



  • >
  • >
  • 6. Let's write it anyway (Sub, End Sub)

  • If you find this site useful, please share and bookmark.


    I'm going to pay close attention to the description,
    If you have any mistakes or suggestions,「Contact Us」I hope you will let me know.
    Use the posted VBA code at your own risk.
    We are not liable for any damages such as data corruption.




    If you find this site useful, please share and bookmark.
    To the bottom of the text