Link to home
Start Free TrialLog in
Avatar of Alex Campbell
Alex CampbellFlag for United States of America

asked on

Need custom function to combine cells in Excel 2010

I need a function where I can give a range such as A2:D2
and have it combine them the text values.
I would also like an option to add a divider.

User generated imageCombine.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joe Howard
Try this:
Public Function CustomCombine(rng As Range, Optional strDivider As String) As String
    Dim cell As Range
    Dim strTemp As String
    If rng.Rows.Count = 1 Then
        For Each cell In rng.Cells
            strTemp = strTemp & cell.Value & strDivider
        Next
    Else
        ' more than 1 row, don't proccess
    End If
    CustomCombine = strTemp
End Function

Open in new window

Avatar of Alex Campbell

ASKER

Great, thanks!