Classified Data: Find All Numbers And Replace Them With X’s In Text
Recently I found myself in a situation where another company wanted to see the formatting of numerous reports and presentations I was routinely putting together. Because I didn’t want the requested data to show our company’s non-public results, I needed to somehow classify the numbers. The method I decided on was to get rid of all the figures and add a numerical placeholder (I designated this with the character ‘x’ for each digit).
Now that I had determined my process, I needed to do a lot of overwriting. At first, I wondered if I could come up with a simple Find/Replace formula that could replace all numbers with an x. Unfortunately, I don’t think Microsoft’s Find/Replace dialog box has that capability (please leave a comment if I’m wrong!). Therefore, I was left with either doing 10 find and replace actions on every file (for digits 0-9) or being a little more creative by writing a VBA macro. What do you think I chose…?
Now I originally made this macro inside PowerPoint but I also went ahead and wrote one for Microsoft Word as well since I could see many people using the functionality inside their documents as well. I skipped making an Excel version because I feel there are simply too many variables to consider in order to make a macro version for general use. However, if you are in need of this functionality inside your Excel spreadsheet, check out this Find & Replace All macro code that I posted to The VBA Vault Blog. It should definitely give you a good start.
The PowerPoint VBA Macro Code
This PowerPoint macro will run through all of the slides in the currently showing presentation and turn any number into an x almost instantaneously! If you need help figuring out where to place the macro code in PowerPoint, check out my post that shows you how to create a personal macro file. You can download the example file at the bottom of this post to play around with it yourself.
Sub ClassifyNumbers() 'PURPOSE: Replace all numerical values with an "x" in the active PowerPoint Presentation 'SOURCE: www.TheSpreadsheetGuru.com Dim fnd As Variant Dim rplc As Variant Dim NumberArray As Variant Dim TxtRng As TextRange Dim TmpRng As TextRange Dim sld As Slide Dim shp As Shape 'Find/Replace Variables NumberArray = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) rplc = "x" 'Loop Through Each Slide For Each sld In ActivePresentation.Slides For y = LBound(NumberArray) To UBound(NumberArray) For Each shp In sld.Shapes fnd = NumberArray(y) If shp.HasTextFrame Then If shp.TextFrame.HasText Then Set TxtRng = shp.TextFrame.TextRange Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _ ReplaceWhat:=rplc, WholeWords:=False) End If End If 'Replace Other Instances (if necessary) Do While Not TmpRng Is Nothing Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _ ReplaceWhat:=rplc, WholeWords:=False) Loop Next shp Next y Next sld MsgBox "All numbers are now classified (ie " & rplc & rplc & ")!" End Sub
The Microsoft Word VBA Macro Code
This Microsoft Word macro will run through all of the pages in the currently showing Word document and turn any number into an x almost instantaneously! If you need help figuring out where to place the macro code in Microsoft Word, check out my post that shows you how to create a personal macro file. You can download the example file at the bottom of this post to play around with it yourself.
Sub ClassifyNumbers() 'PURPOSE: Replace all numerical values with an "x" in the active Word Document 'SOURCE: www.TheSpreadsheetGuru.com Dim rplc As Variant Dim NumberArray As Variant Application.ScreenUpdating = False 'Find/Replace Variables NumberArray = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) rplc = "x" 'Loop through all numbers and replace them For x = LBound(NumberArray) To UBound(NumberArray) With ActiveDocument.Content.Find .Forward = True .Wrap = wdFindStop .Execute _ FindText:=NumberArray(x), _ ReplaceWith:=rplc, _ Replace:=wdReplaceAll, _ MatchCase:=False End With Next x Application.ScreenUpdating = True MsgBox "All numbers are now classified (ie " & rplc & rplc & ")!" End Sub
Now You Can Hide Your Data
The PowerPoint version of this macro saved me a ton of time and I’m glad I am able to share it with you. If you have any questions concerning either of the VBA macros written in this post, please don’t hesitate to leave a comment in the comment section and I will try my best to answer your questions.
Download Example Files
If you would like to get a copy of the files I used throughout this article, feel free to directly download the files by clicking the download button below.
After 10+ years of creating macros and developing add-ins, I've compiled all the hacks I wish I had known years ago!
The Various Ways To Password Protect Excel Worksheets
Restricting Your User's Abilities Microsoft Excel's worksheet password protection options have been known to trip people up from time to...
Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.