Hello world in Excel – How to

Hello world in Excel – How to

Hello world in Excel

This tutorial shows you how to create a hello world macro in Excel.

For the purpose of this lesson, we go through the steps on a PC running the Windows operating system. In addition, these steps should work perfectly in Excel 2007 or higher.

A macro is a set of commands or actions that make it easier for you to perform tasks you plan use often.

Steps to create a macro to show hello world

Follow the steps below to create a macro to display hello world in Excel.

Steps 1 and 2
Steps 1 and 2 - Hello world tutorial
Partial sheet showing Developer ribbon.
  1. In a new or existing sheet, click on a cell. Currently, we are in cell A1. Click on Developer from the toolbar. The Developer ribbon appears.
    Note: If you do not see the Developer command on the toolbar, then follow this quick tip to show it.
  2. Under the Code group, click Record Macro. The Record Macro dialog box appears.

Although it is not necessary, you should give your macro a unique name. Preferably, more than three characters in length.

Steps 3 and 4
Steps 3 and 4 - Record macro dialog box
Record Macro dialog box.
  1. In the Record Macro dialog box, enter a name for your macro in the Macro name input box.
    Note: You should use underscores indicate spaces. Also, we like lowercase or CamelCase. However, you can use any case you like.
  2. Click OK. The recording process starts.

Now, there are two things you may notice.

Hello world - Stop Recording command in Developer ribbon
Partial Developer ribbon showing the Stop Recording option.

Firstly, under the Developer ribbon, the Record Macro option changes to Stop Recording.

Excel status bar showing the stop recording macro icon
Left-side of status bar, showing the stop recording icon.

Secondly, the status bar, at the bottom-left of Excel displays a square icon.

In both cases, you click on these commands to stop recording your macro.


Steps 5 and 6
Steps 5 and 6 - Hello world - Sheet showing "Hello, world!" and the Stop Recording option in the Developer ribbon
Sheet showing “Hello, world!” and the Stop Recording option in the Developer ribbon.
  1. So, we use cell D1 to type “Hello, world!” However, you can type it in any cell.
  2. After you finish typing, press Enter and click Stop Recording from the Developer ribbon. At last, you have just created a macro.

Now that you have your macro set, let us see if it works.


Test your macro

Before we test our macro, clear the sheet. It helps to have a clean sheet for this test. A quick way to clear the sheet is by pressing Ctrl + A, and pressing Delete.

Steps to test your macro

Follow the steps below to test your macro.

Steps 1 and 2
Steps 1 and 2 - Test macro - Hello world. Developer ribbon showing Macros option
Developer ribbon showing Macros option.
  1. Click on any cell on the sheet.
  2. From the Developer ribbon, click the View Macros option, under the Code group. This will open the Macro dialog box.
Steps 3 and 4
Steps 3 and 4 - Select and run your macro from the Macro list
Macro dialog box – Select and run your macro from the Macro list.
  1. From the Macro name list, select the macro you just created.
  2. Click Run. Finally, you should see your “hello world” text in the cell you selected.

Save your hello world macro

Steps 1 and 2 - Hello world - Save your macro
Save As screen, to save your Excel hello world macro.

From the toolbar, select File…Save As. This will open the Save As screen.

  1. Under the Save As screen, give your document a name. In our case, name our document hello_world.
    Then, select Excel Macro-Enabled Workbook (*.xlsm) from the dropdown options, below your filename. This file type will allow you to run your macros in Excel.
  2. Lastly, click Save.

Now, you can use this macro anytime you choose.


Success!

So, were you successful? Congratulations, you did it!

If you had any issues, then give it another shot.


Related


Education home

 

Affiliate stuff – Move up and excel with Excel