Howdy folks. Jeff Weir here. The subject of today’s post is “What would James Bond have in his Personal Macro Workbook”. The Personal Macro Workbook is a secret place where you can save frequently used macros, automation snippets and code modules so that you can call them from any file and save tons of time, not to mention look dashingly good in-front of your boss. In this article, we’ll take a look at how to set up a personal macro workbook and use it.
The other day, undercover Excel secret agent KV came up a great list of interview questions in response to Chandoo’s great article What are best Excel interview questions?
I particularly liked this one:
Do you have a Personal Macro Workbook setup ? If yes, what are the most common macros you use in your daily work?
Secret Agent KV obviously has some purpose-built gadgets stored in his Personal Macro Workbook that he employs to kill inefficiencies. And he obviously also knows the two top-secret reasons to keep code in a Personal Macro Workbook:
- To keep it safe from international spy rings.
- So you can whip it out whenever you are cornered by any evil-looking spreadsheet.
While that first point is important, that second is the clincher: code stored in a personal workbook can be unleashed with a simple judo-chop to the throat. Err, I mean a simple Alt + F8 to the keyboard:

And the best thing of all: this top secret code can be recycled over and over again, just like a James Bond plot!
But I don’t know how to write code… I hear you say. (I’ve bugged your office). Well…does James Bond build his own top-secret gadgets? No, of course not. He has Q to do it for him:

Okay, okay…so you don’t have Q at your disposal. But you do have G:

Google. Because the secret code for world Excel domination has been leaked all over the internet, by the likes of secret agent KV and 10,000 other spooks just like him. Many strains of this code are highly lethal to just about any kind of inefficiency you could ever think of. You just need to cut and paste it into your Personal Macro Workbook and you’re on your way to world Excel Domination.
So in the international war on spreadsheet terror, KV’s on to something. Which is why I asked him if to digital pen to digital paper, and share some more of his ill-gotten top secret code with us here on ExcelWikiLeaks.
Unfortunately for us, he said no. So I told him that unless he complies by this time tomorrow, I’ll publish his real name. So he said yes. (Khushnood Viccaji is obviously a man with something to hide. But don’t worry, Khushnood …your secret identity is safe with me.) So tune in tomorrow to see secret spy code in action.
Meanwhile, I’ll set the scene by showing you where and how to stash your to secret code. And after that, I’ll point you to some code I’ve only just completed that could well save you hours if you use Pivots a lot. So read right to the end, good spooks.
What exactly is a Personal Macro Workbook?
Often on the internet you’ll find workbooks that you can download that contain useful inefficiency-killing code. But those macros are firmly attached to the workbooks they live in. So as long as you have those workbooks open, you can use those macros. But as soon as you close those workbooks, those macros are no longer available.
But just as secret agents have briefcases with false bottoms (and possibly girls with false body-parts), Excel has a hidden workbook – the Personal Macro Workbook – that gets opened automatically any time you start Excel.
So just like James Bond’s hidden gadgets, any code you stash in there is constantly at your command, just waiting to be whipped out and triggered at the slightest provocation. (Which reminds me of another aspect of Mr Bond, but we’ll keep this family friendly for now, eh?)
How do we set up our Personal Macro Workbook?
Note that the Personal Macro Workbook doesn’t exist until we instruct Excel to create it. But that’s simple. If you’ve got Excel 2010, here’s how. (If you’ve got a different version, you may need to do some secret squirrel industrial espionage via Google to get the secret plans for your particular version)
Step One: Make sure the Developer Ribbon has been enabled.
This isn’t strictly necessary, but we’ll go ahead and do it anyway. Have a look at the top of the workbook. Do you have a menu option ‘Developer’ showing?

Yes? Great.
No? No problem, let’s sort that now. Click File, and select the Options option:
Now click Customize Ribbon, and then check the Developer checkbox on the right hand side, then press OK:
Cool, now that Developer option should show in the ribbon.
Step two: Record a ‘dummy’ macro into your Personal Macro Workbook
To create our Personal Macro Workbook, we simply record a macro and tell Excel to put the macro inside it. Excel then realizes “Well, duh…I better create a Personal Macro Workbook first, because it doesn’t actually exist yet”.
To do this, click on the Developer option in the ribbon, which brings up a whole heap of fancy looking options. (Don’t worry, even James Bond doesn’t know what most of these do).
Now click the Record Macro option that shows in the left hand side of the Developer ribbon:
Note that you could also click the exact same icon that you’ll find down the bottom left hand corner of the spreadsheet:
Either way, this brinks up the Record Macro dialog box:
By default, Excel tells you that it will store the macro it’s about to record in This Workbook. But that’s not what we want this time. Instead, we want Excel to store the macro in our Personal Macro Workbook, which will force Excel to create the Personal Macro Workbook.
So change that “Store Macro In” drop-down to this:
Now go ahead and push OK.
Now…I don’t want you to panic or freak out or anything… so promise me you’ll listen very calmly to what I’m about to say. Promise? Okay, good. The Macro Recorder is now recording everything you do. So try not to make any sudden moves or pull any funny faces. Don’t pick your nose. And please, don’t make any loud body noises. Because it’s all going down on tape. Just act normal. (Unless of course you routinely pull funny faces while picking your nose to the tune of loud bodily noises. In which case, give me you best abnormal.) That’s it.
Okay…now we want to carefully stop recording. Why? Because the purpose of this exercise is not to actually create magnificent code, but rather to create a secret compartment within Excel in which to store magnificent code. And merely recording a completely blank macro like we just did is enough to get Excel to create our top secret Personal Macro Workbook.
To shut this thing down, I need you to s-l-o-w-l-y reach into your spy satchel and pull out the red-handled, thin-nosed wire cutters. Now, c-a-r-e-f-u-l-l-y unscrew the bomb housing, and locate the detonator. See the blue wire sticking out of the detonator? C-a-r-e-f-u-l-l-y cut it before the timer goes to Zero.
No, wait a minute…I think it’s the red wire.
NO, WAIT…THAT’S NOT IT EITHER. Umm…ahh…err….Ah…quick…Jeff…think…argggh…Oh No…Mummy!
WAIT, I REMEMBER NOW! To shut this thing down, push the STOP RECORDING buttons in the ribbon:
Alternately, you can click the Stop Recording icon that you’ll find down the bottom left hand corner of the spreadsheet:
Phew, that was close. Sorry about that. Hey, well done, you! Believe it or not, just by setting the macro recorder to Record and then clicking Stop forced Excel to create your very own Personal Macro Workbook. Who said giving birth was hard, eh! So where is this new baby? Well, duh…she’s hidden. I mean, really! Are you fit to be a parent, with an attention span like that?
Alright, alright, if you really want me to prove this immaculate conception, then click View from the top of the ribbon, and then click Unhide:
BEHOLD! A secret hidden workbook called PERSONAL!. Just waiting to be filled with your secret stash of code.
Isn’t she a beautiful baby? Look, she has your father’s eyes! (Don’t bother pushing OK to unhide her…this was just to prove that she exits.)
Step three: Put some re-usable code in there
The easiest way to get code into your Personal Macro Workbook is via something called the Visual Basic Editor, or VBE for short. You can open the VBE by pushing Alt + F11 from Excel. (Pushing Alt + F11 again takes you back to Excel). Go ahead, give it a try. You’ll see something like this:
Scary, isn’t it. It doesn’t look anything like the Excel that we know and love. In fact, it’s about as attractive as a villain from a Bond film. But don’t worry, we’ll defeat this bad boy together.
(Note that depending on your settings, you might see a few more windows than what the above screenshot shows. So just ignore any of the below steps that aren’t relevant.)
The first thing we want to do is to bring up something called the Project Explorer window, which is a tree-map view of all the different workbooks and Add-Ins that you currently have loaded. To make it visible, select Project Explorer from the View tab:
…which will bring up this:
And look…we can already see our new baby listed on the side: Personal.XLSB. This being a spy flick and all, Excel gave our new Personal Macro Workbook the code name XLSB. (Note that if your version of Excel is a little older, you will see Personal.XLS instead. Basically you have the Sean Connery bond, and not the Danial Craig revision. But they are both deadly.)
What we need to do is expand that Personal.XLSB node by clicking on the + sign to the left of it. Here’s what the first level looks like:
So now we see a folder called Microsoft Excel Objects and another one called Modules. The Microsoft Excel Objects node expands out to show us two further nodes called Sheet1 and ThisWorkbook:
…but we don’t use these, so just ignore them. What we want is to expand the Modules node:
Now we just need to double-click on that Module1 thing to bring up the Code Window associated with this module. You might already see a code window, or even a whole bunch of them floating on top of each other. Double-clicking on a particular Module will bring the applicable code window to the top.
And look, there’s that Macro we recorded earlier. That’s not so scary is it…now we know where code turns up when recorded to the Personal Macro Workbook – in a Module. Any time you record a new macro, Excel sticks it in a Module. If you’ve already been recording Macros during your current Excel session, then Excel sticks it in the same Module. If you start a new session (e.g. close down Excel, then restart it and record another Macro) then Excel would put the code you record in a new module. And any time you put new code into a Module – either by using the Macro Recorder or by cutting and pasting code directly in to a Module, then when you close Excel it will prompt you if you want to save changes to your Personal Macro Workbook.
It doesn’t really matter which of the Modules you store your code in in that Personal Macro Workbook – just so long as each routine has a different name. In fact, you can have just one module in there if you like that contains hundreds of different routines. I have several modules, that I’ve given names like modPivotTables and modText and modCharts, with each module containing routines related to the name of the module. I find this makes it easier to track down where a particular routine is stored, in case I want to make changes to it in the future. You can rename Modules by bringing up the Properties window. To do this, select view from the Toolbar, and then click Properties Window:
…which will bring up a new window that will probably sit right below the Project Explorer window by default:

If it’s floating somewhere else, just double-click it and it will then ‘dock’ below the Project Explorer window as shown above. To change the name of a Module, just type the new name where I’ve indicated above.
So now we know where to copy new code, if we want to store it there for reuse. Sweet! So let’s delete that code, and put something useful in there right away, shall we?
So what other kinds of things might you want to put in there?
Well, efficiency comes in all shapes and sizes. I’ve got macros in there that are just a few lines long, and that save me a mere two or three mouse-clicks, like this one:
Sub ClearFormats()
Selection.ClearFormats
End Sub
All that does, is clear the formats from the selected range. In fact, it does exactly the same thing as this does:
...the only difference is that I assign this to a keyboard shortcut of [Ctrl] + [C] so that I don't even have to take my hands off the keyboard to launch it. (Sure, I could use Excel's shortcut of [Alt]+[H]+[E]+[F]. But that's more random digits than my memory or fingers can usually handle.)
Assigning a keyboard shortcut to launch a Macro is easy. First, we switch from the VBE back to Excel using [Alt]+[F11], and then we push [Alt] + [F8] to bring up the Macro Dialog Box:

Then we click the Options button on the bottom right, which brings up the Macro Options dialog box, where we can enter in the key combination we want to use:
I usually use a combination with [Shift] in it, because this stops me overwriting any of Excel's existing keyboard shortcuts.
Can I put clever home-made Worksheet Functions in there too?
You bet. I often store custom-made functions - called User Defined Functions - in my Personal Macro Workbook that can be used within a formula in a cell, without having to even launch the Run Macro dialog box.
For example, say you have some delimited text in a column like so:

Let's say you wanted to extract the 3rd item in that list, but for some reason can't use Text-To-Columns because you don't want to blow your Excel Ninja cover. You'd need a pretty complicated formula to do this. Probably something like this:
=MID(A2,FIND("|",SUBSTITUTE(A2,";","|",2))+1,FIND("|", SUBSTITUTE(A2,";","|",3))-FIND("|",SUBSTITUTE(A2,";","|",2))-1)
That formula is a pain to remember how to put together, not to mention a drag to write. So instead, you could just store the following function in your Personal Macro Workbook:
Function SplitText(str As String, strDelimiter As String, lngOccurance As Long)
Dim varArray As Variant
varArray = Split(Expression:=str, delimiter:=strDelimiter)
SplitText = varArray(lngOccurance - 1)
End Function
Then you could use it in any workbook by using this formula:
=PERSONAL.XLSB!SplitText(A2,";",3)
...for exactly the same effect. But with much less effort.
Note that we have to prefix the formula with PERSONAL.XSLB! so that Excel knows where to find the code behind this puppy.
If you send the workbook to someone else that doesn't have the same Macro in their Personal Macro Workbook, then they will just get a #NAME? Error. To avoid this, you could send them the Macro itself and point them to this article. Or you could copy the code from your Personal Macro Workbook and paste it into a Code Module in the Workbook you are sending. To do this, select the workbook of interest in the VBE, then click INSERT and select Module from the menu, as shown below.
This will put a blank Code Module in the workbook itself, and then you can copy the in the workbook that you are sending out, and then copy the macro from your Personal Macro Workbook into that empty Module:
...and then ditch the =PERSONAL.XLSB bit in your formula:
=ExtractElement(A2,3,";")
Those are fairly trivial, aren't they? What about a really intricate gadget?
At the other extreme, I've got macros in there that I've worked on for months, that save me hours if not days of work. And some let me do the downright impossible.
Here's an example: Imagine you've got a list of 1000 Top Secret Passwords (left) and a PivotTable of 20,000 Top Secret Passwords (right). And imagine that in order to save the world, you need to filter the PivotTable on the right so that it exactly matches the list on the left. Quickly.
How long do you think it's going to take you to filter that pivot using this:
Hours? Days? What if the fate of the free world depends on you getting it right? Worried you might make mistakes? Would you even notice? Would you bother checking? How will you even do this...as that PivotFilter Dialog box says, Not All Items Showing! So we can't even see all items to filter them. Goodbye free world!
Enter my FilterPivot macro, that lives in my Personal Macro Workbook. It's just itching for a fight like this one. Let's judo-chop the keyboard with Alt + F8, bring up the Run Macro dialog box, and see it in action, shall we?
Look, there it is. All I need to do now is select it, push Run, and follow the instructions:
*BING*...Done! See - the PivotTable on the right is filtered so that it exactly matches the list on the left.
How's that. Neat, eh! This code is really, really fast under a range of different scenarios. It works out whether it's quickest to:
- make all items visible in the pivot, and then hide just the PivotItems that don't match the filter terms; or
- hide all but one items in the PivotField, and unhide just the PivotItems that do match the filter terms
If you've got a PivotTable with 20,000 items in it, then here's how long it takes:
- Filter on 100 search terms: 7 seconds
- Filter on 10,000 search terms: 1 minute, 30 seconds
- Filter on 19,900 search terms: 5 seconds
Want one of your very own? Go and visit my recent post Filtering Pivots Based On External Ranges over at the Daily Dose of Excel blog, and cut and paste away. Note that this code requires Excel 2010 or later...and you want to scroll to the end of the acticle and look for the code under the heading Faster Approach. If you've got 2007 or earlier, all is not lost: look for the code listed under the Slower Approach heading. It's not as fast as the times I've posted above, but still a heck of a lot faster than doing it my hand.
That's the beauty of the web - there's weapons-grade code just waiting for you to steal. So again, you don't have to know how to write code in order to highly leverage VBA. All you need to know is how to Google, Cut, and Paste. Heck, even Austin Powers can do that without screwing it up!
That's more than enough for today. Tune in tomorrow, and we'll see what kind of time-savers Secret Agent KV has in his Personal Macro Workbook.
And if you know of amazing routines published on the web somewhere that are Personal Macro Workbook ready, then let us know about them in the comments below. But only if these routines are ready to go, and are the best of the best. Like the code at these two links:
http://peltiertech.com/WordPress/label-last-point-for-excel-2007/
http://datapigtechnologies.com/blog/index.php/auto-format-pivottables-to-match-source-data/
About the Author.
Jeff Weir – a local of Galactic North up there in Windy Wellington, New Zealand – is more volatile than INDIRECT and more random than RAND. In fact, his state of mind can be pretty much summed up by this:
=NOT(EVEN(PROPER(OR(RIGHT(TODAY())))))
That’s right, pure #VALUE!
Find out more at http:www.heavydutydecisions.co.nz









































37 Responses to “Quickly Change Formulas Using Find / Replace”
Chandoo,
this is a really cool stuff what I use quite often. In addtion this method also could be a good choice to switch the reference type of the formulas from relative to absolute or vice versa. (just simply replace the $ in the same way).
Andras
@Andras: you are right, we can use find / replace to change references, reference types etc. Now, only if they had regex in find/ replace, we could so much more 🙂
@Tony Rose: Thank you. This is very useful and powerful feature. I even use it for cleaning up data. While formulas are good, they are not the solution for every problem. Often when I need more powerful cleanup / changing, I copy paste the stuff to text editors like notepad++ and then use their find/replace to do the dirty task.
What if i have to change the formula from ='Analysis'!C1 to 'Analysis 1'!C1?
I tried doing it using Find /Replace but could't. Encountered some errors.
And is there a way to change this using VBA???
Hi,
Did you ever get a reply to this?
Thanks
Ollie
to make your life easier, suggest you to avoid (Space) in worksheet names whenever possible. Consider (underscore) instead.
As the first formula wouldn't have the single apostrophes (since there's no space) need to include that in replace. So, search for:
Analysis
and replace with:
'Analysis 1'
This could be the most useful tips I've seen in a while. I use this all the time and can instantly change 400 formulas with a few clicks. Like so many other functions in Excel, I don't know what I would do without this one.
Keep 'em coming!
[...] on formulas: 5 areas where mouse kicks keyboard’s butt | Edit formulas in bulk using Find / Replace | Excel Formulas Online [...]
THANKS BRO
You, sir, are a god among men...
This is really cool. Your just save me hours of work. Thanks.
Thanks so much for this fix! It saved me tons of work. I'm muddling my way through and this really helped!
Oh... My... God!
This tip just saved me about 2 hours every month! I can't believe how easy it is to use. Now, can somebody tell me who I should call to get a refund for the previous 100 hours I spent manually changing formulas cell by cell?
Thanks so much!
THANK YOU!!!
THANK YOU!!!!
You saved me hours, I had a sheet that has more than 500 formulas, and i needed to replace the year in all of them, you saved me hours
Awesome info on replacing cell addresses in formulas. I have never heard about Ctrl+` before. Thank you!
I have something inside a formula like:
=sum(A1, A2*10) all over I now need to get rid of the *10 {=sume(A1, A2)} I thought to use the find replace trick above but with a blank in the replace but it then outputs just zeros. I thought I could trick it by doing *1 but then it just turns into =*1) with none of my references. Does anyone have an idea how to do this?
The Ctrl+ trick is cool.
@T
Instead of replacing with a blank try replacing
*10)
with
)
Thank you! This literally will save me hours and hours of time, and that's without losing my sanity in the process!
I have Sheet(1), Sheet(2), Sheet(3), etc ... Sheet(100).
Then there's a summary tab where I want to recap information on all those different sheets. Is there anyway to create a formula on the Summary tab to get ='Sheet(1)'!B$29 copied down for all 100 sheets without having to change each sheet # within the formula by hand?
@Brigitte
If you have a list of the sheet names in A2:A100
In B2: =INDIRECT("'"&A2&"'!$B$29")
Copy down
or if you don't have a list of the sheets names you can make it up on the fly
=INDIRECT("'sheet("&ROW()-1&")'!$B$29")
Copy down
Thanks for the suggestion. However, I copied your formula right back to my file and it didn't work. So I did it another way. I put the tab/cell reference in one cell and then did an =INDIRECT() to capture that information.
K2="'Sheet("&L2&")'!B$29" which has a value of 'Sheet(1)'!B$29
B2=INDIRECT(K2) which now has a value of 40 (contents on Sheet(1).
Thank you!!!!
Thank you ..
Hi, Out of all the formulae, I wish to replace the formula which has generated 0 value with blank space? I am unable to do it with find and replace function,
Please suggest.
Thanks.
Chandoo, you literally just saved me about 2 hours of work. I had a document with a daily report in two formats. The second formate just linked to all the appropriate cells in the other format (different sheets). This was 180 references that needed to be changed and I had to make this for a 4 week period (aka 28 different sheets at 180 references to change per sheet).
Thanks so much.
I have tried this way and without using the Ctrl-` formula view
Either way, I am trying to do something simple, but it won't let me.
I have a bunch of cells with a simple math formula like
=-(0.5*20)
various values in each cell, multiplied by 20
I simply want to change the multiplier globally from 20 to 25. But when I tell it to find *20 and replace it with *25, it replaces the entire cell contents with *25, rather than just replacing the *20 portion of the cell contents.
Can anyone assist with this? Seems so simple, but Excel isn't letting me do it.
Search/Replace 20 or 20) with a cell Reference eg A1 or A1)
Then put the value 25 in A1
By using a * in the search it replaces all the text
how to find a specific cell's value in a column & replace replace it with another cell value i actually need a method to replace a data in ca column and replace with the value i have in a specific cell can i give a [ location ] of data to what i need to find and then give row or column range to where i need to find and the given value & then give a [ location ] of data to what i want to be replace with the find and replace by row & column range & than by specific criteria and than by specific location.
please help.
how to find a specific cell’s value in a column & replace replace it with another cell's value.
i actually need a method to find a specific cell's data in a column and replace it with the value i have in a specific cell.
can i give a [ location ] of data to what i need to find and then give row or column range from where i need to find the given value & then give a [ location ] of data to what i want to be replace with.
find and replace by row & column range & than by specific criteria and than by specific location.
please help.
how to find a specific cell’s value in a column & replace it with another cell’s value.
i actually need a method to find a specific cell’s data in a column and replace it with the value i have in a specific cell.
can i give a [ location ] of data to what i need to find and then give row or column range from where i need to find the given value & then give a [ location ] of data to what i want to be replace with.
"find and replace by row & column range & than by specific criteria and than by specific location."
in more than 100 sheets in entire workbook
please help.
This is a great tool, does anyone knows an easiest way??
I'm working with a system that has over 59000 references... so every time the replace all is activated. I lose an entire day.
i actually needs to find cell number "D12" in column "D" and replace with Cell Number "B8" for example
find what = Cell Number "D12" John McNamara
find Where = in Column "D"
Replace with = Cell Number "B8" Bieber D'Souza
Replace Range = Column "D"
In which Sheet = All Sheets in Work Book (more than 100 Sheets)
Note: in every Sheet Cells Number "D12" & "B8" containing Different Employ Name but the find rang and replace rang are same in every sheet and find what cell number and replace with cell number are same also.
please help!
thank you. saved lot of time.
Thank you from the bottom of my heart!
Hi, I am trying to figure out how to use RE to find and replace several values in a column. Using find and replace does not work because of the values I am working with. I have a column with hundreds of rows that have a description of several operating systems and other info, which looks like this: Windows Server 2008 R2 Member Server Security Technical Implementation Guide; Windows 2008 Member Server Security Technical Implementation Guide; Solaris 10 10 SPARC SECURITY TECHNICAL IMPLEMENTATION GUIDE; and Windows Windows 2003 Member Server Security Technical Implementation Guide.
I need to be able to find and replace (or basically curtail the descriptions) to be Windows 2008 R2; Windows 2008; Windows 2003; and Solaris 10. BUT when I run find and replace with just *2008*, it finds every instance, including the ones with R2 at the end. I need it to only change the ones with 2008 to Windows 2008 and the ones that have 2008 R2 to Windows 2008 R2. I know it is possible, but I have no clue on how to write a macro to do this.
Thanks for your help,
Gerard
Wickedly efficient workaround. Excel really is a powerhouse program, all you have to do is dig into it. Ctl ~ exposes the formulas, and Ctl H allows for the multi edit. Brilliant, Chandoo!