A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Extract SSN's from a free form text field...



 
 
Thread Tools Display Modes
  #1  
Old August 20th, 2004, 06:46 PM
Viv
external usenet poster
 
Posts: n/a
Default Extract SSN's from a free form text field...

I am trying to extract SSN's from a free form text field where the SSN
may appear in any portion of the field (beginning, end or middle of
the field).

The SSN will always be preceded by "SS", "SSN", or "SS#".
The SSN may be listed with or without dashes or spaces.
The SSN may be preceded by a dash or space or neither after "SS",
"SSN", or "SS#".


Examples:
Example #1 - SSN-123456789;
Example #2 - CE UNEMPLOYED SS# 987-65-4321 CBR 444-4444 SHADY COVE
Example #3 - SE RETIRED SS 876543219 SE RETIRED OTHER SVC WRKING IN CA

These are a few of the ways the SSN could appear in the field.

If the solution requires programming, please provide exact directions
and expectations. I am not very good with programming. I prefer a
formula if possible.
  #2  
Old August 20th, 2004, 07:33 PM
Ron Rosenfeld
external usenet poster
 
Posts: n/a
Default

On 20 Aug 2004 10:46:56 -0700, (Viv) wrote:

I am trying to extract SSN's from a free form text field where the SSN
may appear in any portion of the field (beginning, end or middle of
the field).

The SSN will always be preceded by "SS", "SSN", or "SS#".
The SSN may be listed with or without dashes or spaces.
The SSN may be preceded by a dash or space or neither after "SS",
"SSN", or "SS#".


Examples:
Example #1 - SSN-123456789;
Example #2 - CE UNEMPLOYED SS# 987-65-4321 CBR 444-4444 SHADY COVE
Example #3 - SE RETIRED SS 876543219 SE RETIRED OTHER SVC WRKING IN CA

These are a few of the ways the SSN could appear in the field.

If the solution requires programming, please provide exact directions
and expectations. I am not very good with programming. I prefer a
formula if possible.


It's easiest with VBA.

I took the approach that, if we remove the space's and hyphens from your
string, a SSN could be uniquely identified by being the first consecutive
string of nine digits after an "SS". If that is not the case, post back with
some more data.

altF11 opens the VB Editor.

Ensure your project is highlighted in the project explorer window, then, from
the main menu bar on top: Insert/Module and paste in the code below.

To use the function, in some cell enter the formula =SSN(cell_ref) where
cell_ref is the address of a string from which you want the SSN extracted.

e.g. =SSN(A1)

The answer should appear as a string of nine digits (or maybe fewer if there
are leading zero's.

Format the result as ssn. Format/Cells/Number/Special/Social Security Number

====================================
Option Explicit

Function SSN(rg As Range) As Long
Dim i As Long
Dim str As String
Dim temp As String

If rg.Count 1 Then Exit Function

str = Replace(rg.Text, "-", "")
str = Replace(str, " ", "")
str = Right(str, Len(str) - InStr(1, str, "SS"))

For i = 1 To Len(str) - 9
temp = Mid(str, i, 9)
If IsNumeric(temp) Then
SSN = temp
Exit Function
End If
Next i
End Function

=================================


--ron
  #3  
Old August 20th, 2004, 07:34 PM
JE McGimpsey
external usenet poster
 
Posts: n/a
Default

one way:

this works with the examples you gave. (Note that I used "SS ", i.e,
with a space after the SS - in one of my substitutions. If that's not
always to be the case, delete the space, but make sure you have no words
prior to the SSN that have "SS" in them):

=MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(S UBSTITUTE(A1, "-",
""), "SSN", "$$$"), "SS#", "$$$"), "SS ", "$$$"), " ", ""), FIND("$$$",
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTI TUTE(A1, "-", ""),
"SSN", "$$$"), "SS#", "$$$"), "SS ", "$$$"), " ", ""))+3, 9)

In article ,
(Viv) wrote:

I am trying to extract SSN's from a free form text field where the SSN
may appear in any portion of the field (beginning, end or middle of
the field).

The SSN will always be preceded by "SS", "SSN", or "SS#".
The SSN may be listed with or without dashes or spaces.
The SSN may be preceded by a dash or space or neither after "SS",
"SSN", or "SS#".


Examples:
Example #1 - SSN-123456789;
Example #2 - CE UNEMPLOYED SS# 987-65-4321 CBR 444-4444 SHADY COVE
Example #3 - SE RETIRED SS 876543219 SE RETIRED OTHER SVC WRKING IN CA

These are a few of the ways the SSN could appear in the field.

If the solution requires programming, please provide exact directions
and expectations. I am not very good with programming. I prefer a
formula if possible.

  #4  
Old August 20th, 2004, 07:38 PM
Biff
external usenet poster
 
Posts: n/a
Default

Hi!

Take your pick: one formula, one UDF:

http://tinyurl.com/6mjoh

Biff

-----Original Message-----
I am trying to extract SSN's from a free form text field

where the SSN
may appear in any portion of the field (beginning, end or

middle of
the field).

The SSN will always be preceded by "SS", "SSN", or "SS#".
The SSN may be listed with or without dashes or spaces.
The SSN may be preceded by a dash or space or neither

after "SS",
"SSN", or "SS#".


Examples:
Example #1 - SSN-123456789;
Example #2 - CE UNEMPLOYED SS# 987-65-4321 CBR 444-4444

SHADY COVE
Example #3 - SE RETIRED SS 876543219 SE RETIRED OTHER SVC

WRKING IN CA

These are a few of the ways the SSN could appear in the

field.

If the solution requires programming, please provide

exact directions
and expectations. I am not very good with programming.

I prefer a
formula if possible.
.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange stLinkCriteria behaviour on command button Anthony Dowd Using Forms 3 August 21st, 2004 03:01 AM
When I space off a text form field the data entered changes jbjoda General Discussion 4 June 15th, 2004 02:48 PM
Calculate in text form field Sherib68 General Discussion 1 June 10th, 2004 08:39 PM
Word 97 and Text Form Field MM General Discussion 1 May 31st, 2004 08:30 AM
Form Doesn't Go To New Record Steve New Users 15 May 16th, 2004 04:33 PM


All times are GMT +1. The time now is 05:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.