offers Excel lesson videos made simple!

Sign up or log in to Magoosh Excel.

5 Excel Macro Examples that Will Make Your Life Easier

As our life gets more and more involved in different programming interfaces, you can easily expect that programming codes will be now included in most of the applications we use in our daily lives. But the question is why? Well, for starters, a programming code can save you a lot of time and work too as they make the repetitive work less so. Using just a bunch of specific instructions, you can control a work that has to be repeated for several times.

The same goes for the Microsoft Excel! Suppose you are working on an Excel worksheet and you need to perform a task say adding to serial numbers. After a certain point in time, you are bound to get frustrated with the ridiculously monotonous work. This is the reason why Excel has certain built-in algorithms that will allow any user to have their work done faster and more easily. What actually needs to be done by the user is to give the instruction sets to the Excel compiler and the job will be done automatically.

Now, these specific instruction codes are known as macros and they help in automating a repeating work. These instructions do not need a programmer’s mind to run; instead, anyone can easily run them in the Excel environment with just a little bit of knowledge about them.

So here we are, with some important excel macro examples that will brighten up your day and reduce that headache of yours!

1. Adding to serial numbers

This macro set will help you to insert the numbers serially until your given condition in a column. The entire process will be automatic, with a new number being written in each new cell.

//MACRO for serial number entry
Sub AddSerialNumbers()
Dim i As Integer
On Error GoTo Last
i = InputBox(“Enter Value”, “Enter Serial Numbers”)
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last: Exit Sub
End Sub

2. Insertion of multiple columns

If you want to insert multiple columns in a given worksheet and you are too worked up to do the same routine work, then follow this macro and solve the problem.

//MACRO for the insertion of the columns

Sub InsertMultipleColumns()
Dim i As Integer
Dim j As Integer
ActiveCell.EntireColumn.Select
On Error GoTo Last
i = InputBox(“Enter number of columns to insert”, “Insert Columns”)
For j = 1 To i
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromRightorAbove
Next j
Last:Exit Sub
End Sub

3. The autofit of the columns

Using this macro, you can easily autofit the cells of the columns in your worksheet. This will reduce the time of manually completing the work by selecting one column at a time.

//MACRO for auto-fitting the columns

Sub AutoFitColumns()
Cells.Select
Cells.EntireColumn.AutoFit
End Sub

4. Unmerge cells

Suppose you need to unmerge a hundred pairs of cells in a given excel worksheet. What will you do? It is one of the famous excel macro examples that has been used for unmerging the cells within the blink of an eye.

//MACRO for unmerging the cells

Sub UnmergeCells()
Selection.UnMerge
End Sub

5. Print selection

This set of instruction will help you to print the pages within a specified range, one that will be set by you.

//MACRO for printing selection range pages

Sub printSelection()\
Selection.PrintOutCopies:=1, Collate:=True
End Sub

Concludingly, it can be said that with the abundant number of macros, working in Excel will be a lot easier. As a certain number of instruction blocks can automate most of the functions, the new method of data entry has become more advanced.

Comments are closed.


Magoosh blog comment policy: To create the best experience for our readers, we will only approve comments that are relevant to the article, general enough to be helpful to other students, concise, and well-written! 😄 Due to the high volume of comments across all of our blogs, we cannot promise that all comments will receive responses from our instructors.

We highly encourage students to help each other out and respond to other students' comments if you can!

If you are a Premium Magoosh student and would like more personalized service from our instructors, you can use the Help tab on the Magoosh dashboard. Thanks!