Classified Data: Find All Numbers And Replace Them With X's In Text

Find and Replace All Numbers in PowerPoint & Microsoft Word

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 replaces  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 Code 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.

See the below code in action!  Click the animated GIF to enlarge.  If you would like to download this file, click the download button located at the bottom of this article.

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.

 

See the below code in action!  Click the animated GIF to enlarge.  If you would like to download this file, click the download button located at the bottom of this article.

 

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's section and I will try my best to answer your questions. 

As always, in order to download this article's example file you will need to be a subscriber of my free tips newsletter. If you click the green button below you can easily sign up and you will be emailed the password to get into the subscribers-only area of this website.

 
                   Already Subscribed? Click HERE to log-in to the "Example Files" section

                   Already Subscribed? Click HERE to log-in to the "Example Files" section

 

How Do I Modify This To Fit My Specific Needs?

Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to getting quick answers to complex problems in Excel, PowerPoint, VBA, you name it

I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).

I wish you the best of luck and I hope this tutorial gets you heading in the right direction!

Chris "Macro" Newman :)