Excel Macros

Excel Macros
6
Jan

Excel Macros

In Excel, Macros allow a user to automate tasks. In this tutorial, you will see how to combine values from two columns into a new third column.

Download the example for the macros tutorial.

Firstly you must enable the use of Macros in the spreadsheet,  so start by using the Developer toolbar. The Developer Toolbar is not seen in the default, so follow these instructions to retrieve it.

Right click anywhere in the top Ribbon and select “Customize the Ribbon”.

The dialog box then lets you check “Developer” in the list on the right, do this and press OK.

The Developer tab is now part of the Ribbon. Click the tab to continue with Excel Macros.

Choose “Insert” on the “Controls” group on the Developer toolbar and select the first option.

Click on anywhere in the spreadsheet, then proceed to name the Macro once the “Assign Macro” dialog box comes up. For this example, it is named Mybutton_click.

Select “New” and the Visual Basic code window will be visible.

After “sub Mybutton_click()” in the formula bar enter the following:
x = 2

Do While Cells(x, 1).Value <> “”

Cells(x, 3).Value = Cells(x, 1).Value + ” ” + Cells(x, 2).Value

x = x + 1

Loop

 

 

That code will “loop” through each individual row, gathering data from the first and second columns, then combining it into the third column to create a full name.

Press the “Play” button in the Visual Basic Editor and the results will populate in the third column.