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?
NYANBCNY32Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

als315Commented:
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

0
SteveCommented:
FYI default for LEFT in Excel is 1 so:

= Left(A2, 1) & Left(B2, 1) & Left(C2, 1)
becomes
= 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!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zack BarresseCEOCommented:
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...

=IF(B1="","",LEFT(B2,1))

HTH

Regards,
Zack Barresse
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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

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

Zack
0
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.