Creating a specialized function in Excel

Is there a way to create a function that would take the first digit on the left in an excel text in 3 separate cells and combine in a new cell.  So if A2 had John, B2 had his Middle Name Charles and C2 had Smith, grab from all 3 so in D2 it would have JCS?
Who is Participating?
SteveConnect With a Mentor Commented:
FYI default for LEFT in Excel is 1 so:

= Left(A2, 1) & Left(B2, 1) & Left(C2, 1)
= Left(A2) & Left(B2) & Left(C2)

And as handling text you would use strings rather than variants:

Public Function initials(A As String, B As String, C As String) As String
    initials = Left(A,1) & Left(B,1) & Left(C,1)
End Function 

Open in new window

VBA does require a length... dunno why.. consistent as ever!
als315Connect With a Mentor Commented:
You can set cell D2 to:
= Left(A2, 1) & Left(B2, 1) & Left(C2, 1)
or create function like:
Public Function initials(A As Variant, B As Variant, C As Variant) As Variant
initials = Left(A, 1) & Left(B, 1) & Left(C, 1)
End Function

Open in new window

Zack BarresseConnect With a Mentor CEOCommented:
NYANBCNY32: Just use the worksheet formula supplied, ignore the VBA. There's no need for it and is less efficient.

If you're not sure if there will be a middle name (or other names) you can wrap the function in an IF() statement. An example would look like this...



Zack Barresse
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

If B1 = ""  then LEFT(B1) = "" 

so why the IF ???
Zack BarresseCEOCommented:
lol yeah, true that. Retarded this morning.

NYANBCNY32Author Commented:
Thank you everyone for your help on the feedback, did set the function as a back-up, but never thought of setting the cells.   Thank you again - Cheers
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.