Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Note: This article has done its job, and will be retiring soon. To prevent "Page not found" woes, we're removing links we know about. If you've created links to this page, please remove them, and together we'll keep the web connected.

In Step 1, you recorded your first VBA macro to delete a row. Let’s now look at the code generated by the macro recorder.

To view the code, click Tools > Macro > Visual Basic Editor. Here’s what you’ll see:

Sub DeleteRow()
'
' DeleteRow Macro
'
'
 Selection.Rows.Delete
 
End Sub

Let’s review each line in this macro:

  1. Sub DeleteRow

    All macros begin with Sub and end with the End Sub keywords. In the above example, DeleteRowis the name of the macro or procedure that you created.

  2. ' DeleteRow Macro

    This is called comments. Comments are useful to describe what's going on in your code. This is especially helpful when your code becomes more complex and other people need to maintain your code, or even when you revisit your code after sometime. Comments always start with a single quote, and the font color becomes green in the Visual Basic Editor to help you differentiate comments from other parts of your code.

  3. Selection.Rows.Delete

    This line of code tells Word what to do. In this case, select the row and delete it.

Now that you have created your first macro and reviewed the basic parts in a macro, let’s move to the next section where you’ll learn a few programming fundamentals.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×