MrExcel Publishing
Your One Stop for Excel Tips & Solutions

len user defined function

Posted by Richard on November 23, 2001 12:59 AM


I am trying to write a userdefined function (if that is the right way to go about it) that will concatenate a zero to a cell if the cell is 11 characters long.

The formula i use at the moment (then pastespecial value) is:


where G2 is the original string


Posted by Bob Umlas on November 23, 2001 7:30 AM

You're writing it as a worksheet formula, not a UDF. I don't think a UDF is necessary, but you can certainly do it:
Function AddZero(Rg as range) as String
If Len(Rg.Value)=11 Then
AddZero="0" & Rg.Value
End If
End Function.
Then, in your worksheet, you can code