+ Reply to Thread
Results 1 to 8 of 8

my join function doesn't work

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    my join function doesn't work

    I am trying to combine several author names semicolon delimited into one cell. The input are author names that are placed in individual cells. To illustrate the question I added an Excel sheet.

    I have a large number of rows with varying numbers of cells containing authors that I all want to combine in this fashion.

    I tried to solve the problem with the join function, but run into trouble. I can't resolve the error. It would be great if somebody could help me out.

    Below is what I tried.

    Range("F1") = Join("A1:C1", ";")
    Attached Files Attached Files
    Last edited by dschmitt; 03-15-2010 at 12:18 AM.

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: my join function doesn't work

    JOIN and SPLIT are possible in VBA but are not standard functions.
    You could use something like this:
    =LEFT(A2 &";"&B2&";"&C2&";"&D2&";"&E2,LEN(A2 &";"&B2&";"&C2&";"&D2&";"&E2)-(5-COUNTA(A2:E2)))
    Change the cells to suit your needs. And change the 5 in the 5-COUNTA to the number of cells in the row.

    For the A, B, and c columns it would be:
    =LEFT(A2 &";"&B2&";"&C2,LEN(A2 &";"&B2&";"&C2)-(3-COUNTA(A2:C2)))

  3. #3
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: my join function doesn't work

    Oops just saw you want a VBA function?
    Let me work on that.

    What was the error you were receiving?

  4. #4
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: my join function doesn't work

    Type mismatch

  5. #5
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: my join function doesn't work

    The Type mismatch is because you are trying to assign an array to a range.

    Here is a UDF.
    Function JoinCell(myRange As Range) As String
    Dim rCell As Range
    For Each rCell In myRange
        JoinCell = JoinCell & ";" & rCell
    Next
        JoinCell = Mid(JoinCell, 2)
    End Function

  6. #6
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: my join function doesn't work

    I somewhat but not completely understand your code.
    I think if you would change your code to be applicable in the example Excel sheet that I attached then I will undertand.

    In the example Excel sheet I tried to combine the array A1:C1 in cell F1.

  7. #7
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: my join function doesn't work

    You can in use it in two ways:
    1) in the sheet itself in F1 enter =joincell(A1:C1)
    2) in VBA
    Range("F1") = Joincell(range("A1:C1"))

  8. #8
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: my join function doesn't work

    I finally got it done. It took a while to sink in.

    I am still a beginner in VBA. I took a couple TurboPascal classes 20 year ago. And this is the first time I defined a function.


    Function JoinCell(myRange As Range) As String
    Dim rCell As Range
    For Each rCell In myRange
        JoinCell = JoinCell & "; " & rCell
    Next
        JoinCell = Mid(JoinCell, 2)
    End Function
    
    Sub Macro3()
    Range("F1") = JoinCell(Range("A1:C1"))
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1