Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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: Changing Months in a Workbook.
Written by Allen Wyatt (last updated November 12, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
It is not unusual to keep track of monthly information, of one sort or another, in a workbook. You might be tracking expenses, sales, inventory movements, stock prices, or any of a thousand other things. When you start a new month, you may make a copy of the previous month's workbook and then look for a way to make changes to the month name that appears in various places in the newly created copy.
If the month name you want to change is stored as text within various worksheets, you can use Excel's find and replace feature to make the changes. Just follow these steps:
If these steps do not change a particular month name as it appears in your workbook, it could be because the month name is not actually text, but a date value formatted to show only the month. In that case, you cannot use Find and Replace; instead you must simply change the date value stored in the cell.
If you want a quick way to change the month names in the worksheet tabs, that is a bit trickier. Excel's find and replace feature won't find or replace the text in tab names. Normally they need to be done by hand, but if you have many of them, you may want to create a macro that will do the changing for you. The following macro prompts you for the text you are searching for and the text you want to replace it with. Then, it steps through each worksheet tab and makes the changes for you.
Sub TabReplace() Dim sFind As String Dim sReplace As String Dim s As Object sFind = InputBox("Text to find?") sReplace = InputBox("Replace it with?") If (sFind & sReplace) > "" Then For Each s In Sheets s.Name = Replace(s.Name, sFind, sReplace) Next s End If End Sub
This macro will run very quickly, but it certainly isn't foolproof. It is very possible that the user could enter illegal characters in either what is being searched for or what it is being replaced with. If you decide to use a macro like this often, you'll want to modify it to test what the user enters.
Even though the steps (and macro) presented here can make the job of updating your workbook easier, it may be easier still to simply rethink how you do your workbook. It may be easier to set up a cell to contain the current month's name, and then reference that name in the appropriate cells throughout the workbook. Then, all you need to do is change the month name in a single cell, and it will be changed elsewhere, automatically. In other ExcelTips you even learned how you can dynamically change a tab name based on the contents of a particular cell.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12275) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Changing Months in a Workbook.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Need to change some cell references in your defined names? Changing one or two is easy; changing dozens is a good deal ...
Discover MoreWouldn't it be great if you could have Excel display some text in a cell only when that cell is empty? Unfortuantely, ...
Discover MoreNeed to get rid of spaces in a range of cells? There are two ways you can approach the task, as described here.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-11-14 04:01:49
sandeep kothari
Thanks Woolley for replying to my query.
2022-11-13 23:20:14
Michael van der Riet
I have a Date tab in my ManAcc workbook. I input the month end date of the active month. From that I get month name in various formats, first day of financial year, last day of financial year, same month last year, etc. etc. It's a good idea to keep global parameters on their own tab.
2022-11-13 09:50:35
J. Woolley
@sandeep kothari
For Each s In Sheets
Sheets is a superset of Worksheets and Charts. You might declare s As Sheet, but there is no Sheet object. Since you don't know whether s will be Worksheet or Chart, you must declare s As Object (general) or As Variant (default).
2022-11-13 06:04:49
sandeep kothari
How does VBA ascertain that the object variable declared as s is worksheet tab name? There are so many objects, like range, workbook, chart etc.
2022-11-12 07:14:05
Tom Santi
Great tip. I just wanted to add that you can combine a cell reference containing a date into otherwise static text to update dates each month. For example, when I was settling my Mom's estate, I had to send certain accountings to the beneficiaries. In the accountings, there were a of lot rows with text and then a date. For example, "Vanguard Account Balance as of November 30, 2015". I didn't want to change all the dates manually each month. So using the & commands, I could get all the dates to update each month by putting the date in a single field. In the example below, cell A1 contains 'November 30, 2015.
The formula is ="Vanguard Account Balance as of"&" "&$A$1. It returns Vanguard Account Balance as of November 30, 2015
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 © 2024 Sharon Parq Associates, Inc.
Comments