Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Counting the Times a Worksheet is Used.
You may want a way to keep track of how many times a particular worksheet is used. There are many ways you can accomplish this. One simple way is to just store the count in the worksheet itself. Right-click a worksheet tab, then choose View Code from the Context menu. Excel displays the Visual Basic Editor, where you should paste the following code:
Private Sub Worksheet_Activate()
Range("A1").Select 'customize Range
ActiveCell = ActiveCell + 1
Range("B1") = "times opened" 'customize Range
End Sub
This code increments the value in cell A1 every time the worksheet is activated. You can modify the cell locations where the macro writes its information, according to your needs.
A more thorough approach is to create a macro that increments named references within the workbook. Consider the following macro:
Function IncrementEventCounter(sName As String, sht As Object)
On Error Resume Next
If sht.Names(sName) Is Nothing Then _
ThisWorkbook.Names.Add "'" & sht.Name & "'!" & sName, "1", False
On Error GoTo 0
With ThisWorkbook.Names("'" & sht.Name & "'!" & sName)
.RefersTo = Val(Mid(.Value, 2)) + 1
End With
End Function
This function is designed to be called from a different macro—one triggered by the event that should cause the usage counter to increment. For instance, if you want to keep track of every time the worksheet is activated, then you would use the following macro as part of the ThisWorkbook object:
Private Sub Workbook_SheetActivate(ByVal sh As Object)
IncrementEventCounter "Activated", sh
End Sub
The macro increments a counter named "Activated" for the worksheet. It does this by calling the IncrementEventCounter macro, with the name of the counter and the name of the worksheet. If, instead, you wanted to count the number of times that a worksheet was changed, you could use the following macro as part of the ThisWorkbook object:
Private Sub Workbook_SheetChange(ByVal sh As Object, _
ByVal Target As Excel.Range)
IncrementEventCounter "Changed", sh
End Sub
The only difference between this macro and the previous one is that it increments a counter named "Changed." To see the values of the counters, just enter a formula in a cell that references the counter. For instance, you could enter =Changed to see the value of the Changed counter, or =Activated to see the value of the Activated counter. The value of each counter will differ from sheet to sheet, since the counters are maintained on a sheet-by-sheet basis.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10544) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Counting the Times a Worksheet is Used.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
If you have a macro that takes a long time to process a workbook, you might want to continue working in Excel while the ...
Discover MoreOne of the powerful programming structures available in VBA is the Select Case structure. This tip explains how you can ...
Discover MoreDoes your macro need to allow the user to specify a particular file name that should be used by the macro? Here's a quick ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2026-10-10 14:18:39
Gary Stockton
I added a unprotect/protect command as well as a workbook save in case user doesn't save, but just views the workbook
ActiveSheet.Unprotect 'since the target cell may be protected, worksheet is unprotected preparing for a change in that cell
Range("M5").Select 'customize Range
ActiveCell = ActiveCell + 1 'incrementing counter
ActiveSheet.Protect ' reprotect the worksheet
ThisWorkbook.Save 'saving the worksheet so that the incremented number is locked in (in case the file closed without saving)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments