8 Excel Macro Examples To Help You Master Macros - Magoosh Excel Blog
8 Excel Macro Examples To Help You Master Macros - Magoosh Excel Blog
Improve
offers yourvideos
Excel lesson Excelmade
skills today!
simple! Navigation Sign
Yes! Get up or log in to Magoosh Excel.
started.
Search...
8 Excel Macro Examples to Help You
Master Macros
BY HARSHITA SRIVASTAVA ON JUNE 18, 2018 IN ADVANCED EXCEL FUNCTIONS AND FORMULAS, BASIC EXCEL FUNCTIONS AND
FORMULAS
Microsoft Excel has been of great help to many of us for a very long time. It has helped us to do our
daily tasks in a much easier and simpler way. It has helped people keep accounts, manage expenses,
manage inventory, and numerous other things as well. Excel has several advanced features too, and
we just need a little guidance to master them. One of these features is of creating macros.
In our daily life, we do a lot of things which are repetitive. We do tasks regularly and periodically and
it would be extremely helpful if some of these repetitive acts could be automated. To do this in Excel,
we use macros.
A macro is like an algorithm or a set of actions that we can use or run multiple times. A macro helps in
automating or repeating tasks by recording or storing our input sequences like mouse strokes or
keyboard presses. Once this input is stored, it makes up a macro which is open to any possible
changes. Thus, we can allow Excel to study our input sequences and then imitate them in order to
generate macros which automate repetitive tasks for us. Due to this outstanding feature,
understanding how to deal with macros is really important.
Here, we will see some examples in order to learn and understand macros perfectly.
As you may know, we can make several worksheets inside each workbook. And there are times we
might want to storeImprove your
a worksheet as aExcel
PDF, orskills today! from
each worksheet Yes!the
Getworkbook
started. as a different or
separate PDF—so here again is macros to the rescue! This is a tedious process if done individually and
manually, but a code can help us achieve the same result in much less time.
In the above code, the worksheet will be saved as a PDF in the folder called ‘Myfile’ on the desktop.
Here is the code we can use. Note that we can even change the color of the duplicated portions along
with finding them:
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 2/7
5/29/2019 8 Excel Macro Examples to Help You Master Macros - Magoosh Excel Blog
‘This code helps in removing any blank sheets that might be present in the workbook
Sub RemoveBlankSheets()
Dim ws As Worksheet
On Error Resume Next
Application.ScreenUpdating= False
Application.DisplayAlerts= False
For Each ws In Application.Worksheets
If Application.WorksheetFunction.CountA(ws.UsedRange) = 0 Then
ws.Delete
End If
Next
Application.ScreenUpdating= True
Application.DisplayAlerts= True
End Sub
‘This is going to highlight and show us the cells that contain comments`
Sub HiLightCellsHavingComments()
ActiveSheet.Cells.SpecialCells(xlCellTypeComments).Interior.Color = vbRed
End Sub
This code highlights the cells having comments in red. We can put in the color of our choice in place of
‘vbRed’ in order to change the color of the highlights.
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 3/7
5/29/2019 8 Excel Macro Examples to Help You Master Macros - Magoosh Excel Blog
‘This is going to count and tell us the number of workbooks which are currently open but not saved`
Sub Currentbooks()
Dim Wb As Workbook
Dim in As Integer
For Each book In Workbooks
If Wb.Saved = False Then
in = in + 1
End If
Next Wb
MsgBox in
End Sub
Once you know the number of books which are open and unsaved, you can find them and save them
to prevent loss of work.
Microsoft Excel with its numerous features can be extremely helpful to users. The excellent feature of
macros increases efficiency and saves a lot of time. It is because of such features that Excel has
become mandatory in almost all professional walks of life. For some people writing code was only
associated with various programming languages; but to the contrary, Excel opens up a whole new
world with codes of macros. With a little time and effort, you can definitely learn how to create macros
to get the most out of Excel. Go ahead and learn these amazing advanced features of Microsoft Excel.
All the best!
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 4/7
5/29/2019 8 Excel Macro Examples to Help You Master Macros - Magoosh Excel Blog
Related Posts
Improve your Excel skills today! Yes! Get started.
5 Excel Macro How to Create a Macro How to Use VLOOKUP Use this Excel
Examples that Will in Excel in Excel Functions List to
Make Your Life Easier Improve Your
Efficiency
Previous Next
No comments yet.
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!
Leave a Reply
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 5/7
5/29/2019 8 Excel Macro Examples to Help You Master Macros - Magoosh Excel Blog
Name (required)
Website
SUBMIT COMMENT
Recent Posts
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 6/7
5/29/2019 8 Excel Macro Examples to Help You Master Macros - Magoosh Excel Blog
© 2019 Magoosh Excel Blog. All Rights Reserved.
Improve your Excel skills today! Yes! Get started.
https://magoosh.com/excel/8-excel-macro-examples-to-help-you-master-macros/ 7/7