Excel 2007 custom function using case statement and cell reference

I need to create a custom excel 2007 function that does the following:

case value in columnA ='Tech' output=columnB concatenated with columnC

case value in columnA ='Session' output=columnD concatenated with columnE

case value in columnA ='Poster' output=columnF concatenated with columnG

Basically based upon the value in column A I will be concatenating 2 other columns for the output

Whatever column I run this function in should always reference the value in column A for that row.

Can anyone supply some basic code samples that I can try?

Thanks
TOWELLRAsked:
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.

Martin LissOlder than dirtCommented:
Here's a UDF you can use. Insert the code in a module. Then in column H1 or wherever =concat(A1) and copy down


Function Concat(cel As Variant) As Variant
    Select Case cel
        Case "Tech"
            Concat = cel.Offset(0, 1) & cel.Offset(0, 2)
        Case "Session"
            Concat = cel.Offset(0, 3) & cel.Offset(0, 4)
        Case "Poster"
            Concat = cel.Offset(0, 5) & cel.Offset(0, 6)
        Case Else
            Concat = "?"
    End Select

Open in new window

0
SteveCommented:
I would always feed all cells into the formula:

Function Concat(celA As String, celB As String, celC As String, celD As String, celE As String, celF As String, celG As String) As String

    Select Case celA
        Case "Tech"
            Concat = celB & celC
        Case "Session"
            Concat = celD & celE
        Case "Poster"
            Concat = celF & celG
        Case Else
            Concat = "?"
    End Select

End Function

Open in new window


In Martins code any changes to the cells in B to G will not recalculate the result of the formula.
(so the formula will not update with cell changes)
Concat.xlsm
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
Martin LissOlder than dirtCommented:
@The_Barman: You're right. That's an oversight on my part.
0
Martin LissOlder than dirtCommented:
Did any of the above help you?
0
TOWELLRAuthor Commented:
Works perfectly.  Have expanded this to incorporate more complicated string building.
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 Applications

From novice to tech pro — start learning today.