Format SSN to last 4 digits

jennvkerr

New Member
Joined
Jun 21, 2012
Messages
21
Hi there! I have a column with social security numbers, i.e. 555-33-2222 and I need to change to show only the last four digits, i.e. xxx-xx-2222. Can this be done in excel?

Thanks so much!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi there! I have a column with social security numbers, i.e. 555-33-2222 and I need to change to show only the last four digits, i.e. xxx-xx-2222. Can this be done in excel?
Are you looking to hide the beginning part of SSN within the cells that contain them or, as VoG has done, display the modified SSN in some other cell? If you wanted to hid the beginning part within their cells, then you do realize the full SSN will be displayed in the Formula Bar when that cell is selected (or will you have selection of that column turned off)?
 
Upvote 0
Are you looking to hide the beginning part of SSN within the cells that contain them or, as VoG has done, display the modified SSN in some other cell? If you wanted to hid the beginning part within their cells, then you do realize the full SSN will be displayed in the Formula Bar when that cell is selected (or will you have selection of that column turned off)?

Its ok if the full SSN appears in the formula bar... just when printing i need those other characters hidden. thank you!
 
Upvote 0
Its ok if the full SSN appears in the formula bar... just when printing i need those other characters hidden. thank you!
First off, I am assuming your SSN's have been entered as 9-digit numbers and then formatted to look like an SSN (otherwise they would be text and you cannot change the cell format of text). If that is the case (or if you just use Excel's Replace dialog box to remove the dashes to you have real numbers in the column), then you can use this macro to toggle back-and-forth between full SSN's and SSN's encoded with the X's...
Code:
Sub ToggleVisibilityOfSSN()
  Dim X As Long, LastRow As Long
  Const SSNcolumn As String = "C"
  Const StartRow As Long = 2
  LastRow = Cells(Rows.Count, SSNcolumn).End(xlUp).Row
  For X = StartRow To LastRow
    If Mid(Cells(X, SSNcolumn).NumberFormat, 2, 1) = "X" Then
      Cells(X, SSNcolumn).NumberFormat = "000-00-0000"
    Else
      Cells(X, SSNcolumn).NumberFormat = """XXX-XX-" & Right(Cells(X, SSNcolumn).Value, 4) & """"
    End If
  Next
End Sub
EDIT NOTE
---------------
I forgot to mention... you have to verify the assumed column letter designation and start row for your SSN's. They are located in the Const (constant) statements.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top