Mac Productivity Programming

Use Macros in Excel on Mac to Save Time and Do More

Michael McConnell 20-02-2018

Excel on the Mac has not always been the same powerhouse it was on Windows. Macros really wouldn’t work unless they were created exclusively for the Mac.


Starting in 2013, Microsoft brought back macros. There are two types of macros: those you can create by quickly recording your actions, and those that use VBA to design more advanced automations. With Office 2016, Excel is using the same codebase on all platforms. This change will make it easier for macros to work across platforms.

So let’s take a look at how this currently works on macOS.

Enabling Macros in Excel on Mac

Working with macros in Excel on your Mac may not be enabled by default. This setting is because macros can be a possible malware vector. The easiest way to tell is to see if you have the Developer tab available on the Ribbon in Excel. If you don’t see it, it is simple to enable.

macros in excel on mac to save time

Click on Excel in the menu bar, and then select Preferences in the dropdown. In the menu, click on Ribbon & Toolbar. In the right-hand list, Developer should be at the bottom, click the checkbox. Finally, click Save and you should see the Developer tab show up at the end of the Ribbon.


After you create each workbook with macros, save it in a new format .xlsm to use the macros after reopening the file. If you forget, Excel will remind you each time you try to save. You’ll also need to enable macros every time you open the file.

Manually Recording a Macro in Excel on Mac

Though you can code macros, that might not be for everyone. If you’re not ready to start working with VBA, Excel lets you record the steps for your macro in an existing sheet. Click on the Developer tab to see your options.

macros in excel on mac to save time

You’re looking for the third option in the Ribbon, Record Macro. Click this, and a dialog pops up allowing you to name your macro and set a keyboard shortcut. You can scope your macro to the Current Workbook, a New Workbook, or in your Personal Macro Workbook. The Personal Macro Workbook is in your user profile and lets you use your macros between your files.


Once you record your actions, they are available on this same tab. Clicking macros will bring up the saved macros in your workbook. Click on your macro name and click Run to run your recorded actions.

Example 1: Daily Sales Total and Hourly Average

For an example macro, you are going to run through a daily sales sheet, with the sales broken down by hourly totals. Your macro is going to add a daily sales total, and then add an average in the last column of each hourly period. If you work in retail or other sales position, this is a helpful sheet to track revenue.

We need to set up the first sheet. Using this first blank as a template to copy into a new tab each day could save you some time. In the first column/row put Hour/Date. Across the top add Monday through Friday.

Then in the first column put a break down of hourly totals from 8-5. I used 24-hour time, but you can use AM/PM notation if you prefer. Your sheet should match the screenshot above.


macros in excel on mac to save time

Add a new tab, and copy your template into it. Then fill out your sales data for the day. (If you don’t have data to populate this sheet, you can enter =RandBetween(10,1000) in all the cells to create dummy data.) Next, click on Developer in the Ribbon.

Then, click on Record Macro. In the dialog enter the name as AverageandSum and leave it stored in This Workbook. You can set a shortcut key if you like. You can enter a description if you need more details on what the macro does. Click okay to start setting up the macro.

At the bottom of the hourly listings enter Daily Totals. In the cell next to it, enter =SUM(B2:B10). Then copy and paste that into the rest of the columns. Then in the header add Average after the last column. Then in the next cell down, enter =Average(B2:F2). Then, paste that into the cells in rest of the column.


Then click Stop Recording. Your macro is now able to use on each new sheet you add to your workbook. Once you have another sheet of data, go back to Developer and click Macros. Your macro should be highlighted, click run to add your sums and averages.

This example can save you a couple of steps, but for more complex actions that can add up. If you do the same operations on data with identical formatting, use recorded macros.

VBA Macros in Excel on Mac

Manually recorded macros in Excel help with data that is always in the same size and shape. It is also useful if you want to perform actions on the entire sheet. You can use your macro to prove the problem.

macros in excel on mac to save time

Add another hour and day to the sheet and run the macro. You’ll see the macro overwrites your new data. The way we get around this is using code to make the macro more dynamic using VBA, which is a slimmed down version of Visual Basic. The implementation focuses on automation for Office.

macros in excel on mac to save time

It is not as easy to pick up as Applescript What Is AppleScript? Writing Your First Mac Automation Script AppleScript can help you automate repetitive tasks on your Mac. Here's an overview and how to write your first AppleScript script. Read More , but Office’s automation is entirely built around Visual Basic. So once you work with it here, you are quickly able to turn around and use it in other Office apps. (It can also be a big help if you’re stuck with a Windows PC at work.)

When working with VBA in Excel, you have a separate Window. The screenshot above is our recorded macro as it appears in the code editor. The windowed mode can be helpful to play around with your code as you’re learning. When your macro gets hung up, there are debugging tools to look at the state of your variables and sheet data.

Office 2016 now comes with the full Visual Basic editor. It allows you to use the Object Browser and debugging tools that used to be limited to the Windows version. You can access the Object Browser by going to View > Object Browser or just press Shift + Command + B. You can then browse through all the classes, methods, and properties available. It was very helpful in constructing the code in the next section.

Example 2: Daily Sales Total and Hourly Average With Code

Before you start coding your macro, let’s start by adding a button to the template. This step makes it much easier for a novice user to access your macro. They can click a button to call the macro rather than digging into the tabs and menus.

macros in excel on mac to save time

Switch back to the blank template sheet you created in the last step. Click on Developer to get back to the tab. Once you’re on the tab, click on Button. Next, click somewhere in the sheet on the template to place the button. The macros menu comes up, name your macro and click New.

The Visual Basic Window will open up; you’ll see it listed as Module2 in the project browser. The code pane will have Sub AverageandSumButton() at the top and a few lines down End Sub. Your code needs to go between these two, as it is the beginning and the end of your macro.

Step 1: Declaring Variables

To begin, you will need to declare all of your variables. These are in the code block below, but a note about how they are constructed. You should declare all variables using Dim before the name, and then as with the datatype.

Sub AverageandSumButton()
  Dim RowPlaceHolder As Integer
  Dim ColumnPlaceHolder As Integer
  Dim StringHolder As String
  Dim AllCells As Range
  Dim TargetCells As Range
  Dim AverageTarget As Range
  Dim SumTarget As Range

Now that you have all of your variables, you need to use some of the range variables right away. Ranges are objects that hold sections of the worksheet as addresses. The variable All Cells will be set to all the active cells on the sheet, which includes the column and row labels. You get this by calling the ActiveSheet object and then it’s UsedRange property.

The problem is you don’t want the labels included in the average and sum data. Instead, you’ll use a subset of the AllCells range. This will be the TargetCells range. You manually declare its range. Its start address is going to be the cell at the second row in the second column of the range.

You call this by calling your AllCells range, using its Cells class to get that specific cell using (2,2). To get the final cell in the range, you will still call AllCells. This time using SpecialCells method to get the property xlCellTypeLastCell. You can see both of these in the code block below.

  Set AllCells = ActiveSheet.UsedRange
  Set TargetCells = Range(AllCells.Cells(2, 2), AllCells.SpecialCells(xlCellTypeLastCell))

Step 2: For Each Loops

The next two sections of code are For Each The Absolute Basics Of Programming For Beginners (Part 2) In part 2 of our absolute beginners guide to programming, I'll be covering the basics of functions, return values, loops and conditionals. Make sure you’ve read part 1 before tackling this, where I explained the... Read More loops. These loops go through an object to act on each subset of that object. In this case, you are doing two of them, one for each row and one for each column. Since they are almost exactly the same, only one of them is here; but both are in the code block. The details are virtually identical.

Before you start the loop for each row, you need to set the target column where the loop writes the average of each row. You use the ColumnPlaceHolder variable to set this target. You set it equal to the Count variable of the Cells class of AllCells. Add one to it to move it to the right of your data by appending +1.

Next, you are going to start the loop by using For Each. Then you want to create a variable for the subset, in this case, subRow. After the In, we set the main object we are parsing TargetCells. Append .Rows at the end to limit the loop to only each row, instead of every cell in the range.

Inside the loop, you use the ActiveSheet.Cells method to set a specific target on the sheet. The coordinates are set by using subRow.Row to get the row the loop is currently in. Then, you use ColumnPlaceHolder for the other coordinate.

You use this for all three steps. The first you append .value after the parentheses and set equal to WorksheetFunction.Average(subRow). This writes the formula for the average of the row into your target cell. The next line you append .Style and set that equal to “Currency”. This step matches the rest of your sheet. On the last line, you append .Font.Bold and set it equal to True. (Note there are not quotes around this one, as it is the boolean value.) This line bolds the font to make the summary info stand out from the rest of the sheet.

Both steps are in the code example below. The second loop swaps rows for columns and changes the formula to Sum. Using this method ties your calculations to the format of the current sheet. Otherwise, its linked to the size at the time you record the macro. So when you work more days or hours, the function grows with your data.

  ColumnPlaceHolder = AllCells.Columns.Count + 1
  For Each subRow In TargetCells.Rows
  ActiveSheet.Cells(subRow.Row, ColumnPlaceHolder).Value = WorksheetFunction.Average(subRow)
  ActiveSheet.Cells(subRow.Row, ColumnPlaceHolder).Style = "Currency"
  ActiveSheet.Cells(subRow.Row, ColumnPlaceHolder).Font.Bold = True
  Next subRow
  RowPlaceHolder = AllCells.Rows.Count + 1
  For Each subColumn In TargetCells.Columns
  ActiveSheet.Cells(RowPlaceHolder, subColumn.Column).Value = WorksheetFunction.Sum(subColumn)
  ActiveSheet.Cells(RowPlaceHolder, subColumn.Column).Style = "Currency"
  ActiveSheet.Cells(RowPlaceHolder, subColumn.Column).Font.Bold = "True"
  Next subColumn

Step 3: Label Your Summaries

Next, label the new row and column, set RowPlaceHolder and ColumnPlaceHolder again. First, use AllCells.Row to get the first row in the range, and then AllCells.Column+1 to get the last column. Then you will use the same method as the loop to set the value to “Average Sales”. You’ll also use the same .Font.Bold property to bold your new label.

macros in excel on mac to save time

Then reverse it, setting your placeholders to the first column and last row to add “Total Sales”. You want to bold this as well.

Both steps are in the code block below. This is the end of the macro noted by End Sub. You should now have the entire macro, and be able to click the button to run it. You can paste all these code blocks in order into your excel sheet if you want to cheat, but where is the fun in that?

  ColumnPlaceHolder = AllCells.Columns.Count + 1
  RowPlaceHolder = AllCells.Row
  ActiveSheet.Cells(RowPlaceHolder, ColumnPlaceHolder).Value = "Average Sales"
  ActiveSheet.Cells(RowPlaceHolder, ColumnPlaceHolder).Font.Bold = True
  ColumnPlaceHolder = AllCells.Column
  RowPlaceHolder = AllCells.Rows.Count + 1
  ActiveSheet.Cells(RowPlaceHolder, ColumnPlaceHolder).Value = "Total Sales"
  ActiveSheet.Cells(RowPlaceHolder, ColumnPlaceHolder).Font.Bold = True
End Sub

What’s Next for Macros in Excel on Mac?

Recorded macros are great to use for predictable repetition. Even if it’s something as simple as resizing all cells and bolding headers, these can save you time. Just avoid common macro mistakes 4 Mistakes to Avoid When Programming Excel Macros With VBA Simple code is vital for Microsoft Excel power users. But how can you make or safely exit a for loop using VBA in Excel? Read More .

Visual Basic opens the door for Mac Excel users to dig deep into Office automation. Visual Basic was traditionally only available on Windows. It allows your macros to adapt to the data dynamically, making them more versatile. If you have the patience, this can be the doorway to more advanced programming.

Want more time-saving spreadsheet tricks? Learn how to highlight specific data automatically with conditional formatting in Excel Automatically Format Data in Excel Spreadsheets With Conditional Formatting Excel's conditional formatting feature lets you format individual cells in an Excel spreadsheet based on their value. We show you how to use this for various everyday tasks. Read More and conditional highlighting in Numbers on Mac How to Use Conditional Formatting in Numbers on Mac Conditional formatting makes your spreadsheets stand out. Here's how to use conditional formatting in Numbers on Mac. Read More .

Related topics: Microsoft Excel, Visual Basic Programming.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. DrShowMe
    March 7, 2018 at 3:19 am

    I am a Mac user who has written (conservative estimate) 150 VBA macros for Excel and Word (mostly Excel). As I have programming experience dating back more years than I care to admit (and several programming languages), I did not find VBA to be challenging. However, ... many Office for Mac versions (I am using 2011) DO NOT INCLUDE VBA help. This disappeared somewhere along the line. In my case, I had enough experience by then to not be impacted, but a new user would surely find that a major issue.

    Second, macros can be executable code or functions. The latter are useful in other macros. A function, Fcn, is used within other code as Fcn (a, b) where a and b are the values operated on by the function Fcn.

    Another advice I would add is to document all the steps in your VBA macro with comment lines (these are lines starting with the ' character). Use these to identify the meaning of all your variables AND what each section of code is intended to do. Regardless of the quality of your memory, this will facilitate the inevitable corrections you will want to make or using the code in new macros. Following is code including comments from two of my Excel macros (a function and a procedure identifying info blocked) as an example [the reason for them is irrelevant, the point is the use of comments to document the code; the lines with just a ' are used for vertical spacing; copying what follows into a word processor will make it easier to read]:
    Function ExParse(Old As String) As String
    ' ExParse Function
    ' Function created by XXXXXX, on 8 February 2003
    ' Copyright XXXXXX, February 2003, All rights reserved
    ' ExParse returns the string Old with the "|" cleaned out and replaced with Y, M, and D
    ' If the string old will be ambiguous, the value of ExParse is "Manual"
    ' ExParse requires these user-defined functions:
    ' - HowMany
    ' - FindIt (indirect)
    Dim NumD, NumM, NumY, NumPole As Integer
    ' NumY, NumM, NumD, and NumPole are the number of Y, M, D, and "|", respectively, found in Old
    ExParse = Old
    ' Eliminate the character "|" at the right end of string
    If Right(Old, 1) = "|" Then
    ExParse = Left(Old, Len(Old) - 1)
    End If
    ' If the string is ambiguous, get out
    NumD = HowMany("D", ExParse)
    NumM = HowMany("M", ExParse)
    NumY = HowMany("Y", ExParse)
    NumPole = HowMany("|", ExParse)
    If (NumD > 1) Or (NumM > 1) Or (NumY > 1) Or (NumPole > 0) Then
    ExParse = "Manual"
    End If

    End Function 'ExParse
    Sub SpaceRemover()
    ' SpaceRemover Macro
    ' Macro created by XXXXXX, on 22 April 2010
    ' Copyright, XXXXXX, April 2010, All rights reserved.
    ' SpaceRemover removes one or two leading or trailing space characters from
    ' every cell in an input range. Those are data input errors that are difficult
    ' to pick up in proofreading.
    ' SpaceRemover requires NO user-defined functions
    Dim FirstRow As Integer
    Dim LastRow As Long
    Dim FirstColumn As Integer
    Dim LastColumn As Integer
    Dim J As Long
    Dim K As Long
    Dim Temp As String
    ' FirstRow, LastRow, FirstColumn, and LastColumn define the area on the spreadsheet
    ' to be checked
    ' J is a loop counter across the columns
    ' K is a loop counter across the rows
    ' Temp is a temporary string to hold the cell value
    ' Get the FirstRow, LastRow, FirstColumn, and LastColumn numbers
    FirstRow = InputBox("What is the number of the first row?")
    LastRow = InputBox("What is the number of the last row?")
    FirstColumn = InputBox("What is the number of the first column?")
    LastColumn = InputBox("What is the number of the last column?")
    ' Loop through the cells in the defined area
    For J = FirstColumn To LastColumn
    For K = FirstRow To LastRow
    ' Set Temp to the cell contents
    Temp = Cells(K, J).Formula
    ' If the cell contains a formula, leave it alone
    If Left(Temp, 1) = "=" Then
    GoTo Skipping
    End If
    ' Remove a leading or trailing space charater (twice)
    If Temp "" Then
    If Right(Temp, 1) = " " Then
    Temp = Left(Temp, Len(Temp) - 1)
    End If
    If Right(Temp, 1) = " " Then
    Temp = Left(Temp, Len(Temp) - 1)
    End If
    If Left(Temp, 1) = " " Then
    Temp = Right(Temp, Len(Temp) - 1)
    End If
    If Left(Temp, 1) = " " Then
    Temp = Right(Temp, Len(Temp) - 1)
    End If
    End If
    ' Set the cell contents back to (possibly revised) Temp
    Cells(K, J).Formula = Temp
    Next ' K
    Next ' J

    End Sub ' SpaceRemover