Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Help and How-to
Search
Search
 
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Display only the last four digits of identification numbers
 

Let's say, for common security measures, you want to display only the last four digits of an identification or Social Security number, credit card number, or other number and replace the rest of the digits with asterisks. Whether the digits in your cell are formatted as text, numbers, or the special Social Security number format, you can use the same functions. To display only the last four digits of identification numbers, use the CONCATENATE, RIGHT, and REPT functions.

Example

The example may be easier to understand if you copy it to a blank worksheet.

ShowHow to copy an example

  1. Create a blank workbook or worksheet.
  2. Select the example in the Help topic.

    Note  Do not select the row or column headers.

    Selecting an example from Help

    Selecting an example from Help

  3. Press CTRL+C.
  4. In the worksheet, select cell A1, and press CTRL+V.
  5. To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Tools menu, point to Formula Auditing, and then click Formula Auditing Mode.
 
1
2
3
A B
Type Data
Social Security Number 555-55-5555
Credit Card Number 5555-5555-5555-5555
Formula Description (Result)
=CONCATENATE("***-**-", RIGHT(B2,4)) Combines the last four digits of the SSN with the "***-**-" text string (***-**-5555)
=CONCATENATE(REPT("****-",3), RIGHT(B3,4)) Repeats the "****-" text string three times and combines the result with the the last four digits of the credit card number w(****-****-****-5555)

Security  In the example, you should hide column B and protect the worksheet so that the original data cannot be viewed. For more information, see Hide or display rows and columns and Protect worksheet or workbook elements.

Function details

CONCATENATE

RIGHT, RIGHTB

REPT

advertisement