Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Simple SSN UDF

Hello. I am struggling with my VBA knowledge. I would like to convert the
following formula into a UDF (=ssn(cell)), but I do not know what the code
will look like. Can anyone help?

Formula:
=text(cell, "000-00-0000")

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Simple SSN UDF

Function ssn(myrange As Range)
ssn = Format(myrange.Value, "000-00-0000")
End Function

--
p45cal


"ToddEZ" wrote:

Hello. I am struggling with my VBA knowledge. I would like to convert the
following formula into a UDF (=ssn(cell)), but I do not know what the code
will look like. Can anyone help?

Formula:
=text(cell, "000-00-0000")

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Simple SSN UDF

works perfect. Thank you kindly.

"p45cal" wrote:

Function ssn(myrange As Range)
ssn = Format(myrange.Value, "000-00-0000")
End Function

--
p45cal


"ToddEZ" wrote:

Hello. I am struggling with my VBA knowledge. I would like to convert the
following formula into a UDF (=ssn(cell)), but I do not know what the code
will look like. Can anyone help?

Formula:
=text(cell, "000-00-0000")

Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Simple SSN UDF

What if you make a mistake and only enter 7 or 8 digits... do you want the
function to automatically add 2 or 1 leading zero automatically? Or enter
12e3? Or if you want to feed it a numeric constant like =SSN(123456789)?

Rick


"ToddEZ" wrote in message
...
works perfect. Thank you kindly.

"p45cal" wrote:

Function ssn(myrange As Range)
ssn = Format(myrange.Value, "000-00-0000")
End Function

--
p45cal


"ToddEZ" wrote:

Hello. I am struggling with my VBA knowledge. I would like to convert
the
following formula into a UDF (=ssn(cell)), but I do not know what the
code
will look like. Can anyone help?

Formula:
=text(cell, "000-00-0000")

Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Simple SSN UDF

Hello. I am struggling with my VBA knowledge. I would like to convert
the
following formula into a UDF (=ssn(cell)), but I do not know what the code
will look like. Can anyone help?

Formula:
=text(cell, "000-00-0000")


Place this code in a Module (Insert/Module from the VBE menu)...

Function SSN(ByVal ValueIn As Variant) As String
Dim Temp As String
If TypeOf ValueIn Is Range Then
Temp = ValueIn.Value
Else
Temp = ValueIn
End If
Temp = Replace(Temp, "-", "")
Application.EnableEvents = False
If Temp Like "#########" Then
SSN = Format$(Temp, "@@@-@@-@@@@")
Else
' Not sure what you want to do
' if the value passed in is not
' a valid as a SSN "shape", so
' I am doing nothing here which
' means the original value will
' be returned unaltered
SSN = Temp
End If
Application.EnableEvents = True
End Function


Rick



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Make it more simple or intuitive to do simple things Vernie Charts and Charting in Excel 1 March 16th 05 04:01 AM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"