+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Join does not work

    I have the following function
    Code:
    Function ConCatStr(MyRng As Range, MyDelimiter As String) As String
    Dim Ccell As Range
      For Each Ccell In MyRng
        ConCatStr = ConCatStr & MyDelimiter & CStr(Ccell.Value)
      Next
    ConCatStr = Right(ConCatStr, Len(ConCatStr) - Len(MyDelimiter))
    End Function
    This works, but I was looking at function JOIN() and came up with

    Code:
    Function ConCatStr2(MyRng As Range, MyDelimiter As String) As String
    Dim MyArray
      MyArray = MyRng.Value
      ConCatStr2 = Join(MyArray, MyDelimiter)
    End Function
    Obviously the second has a lot of disadvantages, but I just wanted it to work with a single dimensional range A1:A3. Why doesn't it?
    Last edited by rwgrietveld; 01-12-2010 at 08:54 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Join does not work

    You would need to transpose your range such that you end up with a single dimension array

    Code:
    MyArray = Application.Transpose(MyRng.Value)
    (were MyRng a horizontal vector rather than vertical vector then you would Transpose twice to get single dimension array)

  3. #3
    Forum Moderator romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Alibi
    MS-Off Ver
    All
    Posts
    8,262

    Re: Join does not work

    Because if you assign the value of a range in one go like that, you always get a 2D array.
    So long, and thanks for all the fish.

  4. #4
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Join does not work

    Well,

    That sums it up.

    THX RS and DO.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  5. #5
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Join does not work

    And you can't use Join with a Variant.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Guru Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Join does not work

    Quote Originally Posted by shg View Post
    And you can't use Join with a Variant.
    Shg - don't think that's correct. In the Immediate window the following works without issue:

    Code:
    v = Array(1,2,3)
    
    ?Join(v)
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  7. #7
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,134

    Re: Join does not work

    Ya know, that had always puzzled me. I reckon I never got the syntax correct:
    Code:
    Function CatVec(r As Range, Optional sSep As String = " ") As String
        With WorksheetFunction
            If r.Rows.Count > 1 And r.Columns.Count > 1 Then
                CatVec = "Vectors only!"
            ElseIf r.Rows.Count > 1 Then
                CatVec = Join(.Transpose(r.Value), sSep)
            ElseIf r.Columns.Count > 1 Then
                CatVec = Join(.Transpose(.Transpose(r.Value)), sSep)
            Else
                CatVec = CStr(r.Value)
            End If
        End With
    End Function
    Thank you, Richard.
    Last edited by shg; 01-12-2010 at 11:56 AM.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0