I have the following function
This works, but I was looking at function JOIN() and came up withCode: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
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?Code:Function ConCatStr2(MyRng As Range, MyDelimiter As String) As String Dim MyArray MyArray = MyRng.Value ConCatStr2 = Join(MyArray, MyDelimiter) End Function
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
You would need to transpose your range such that you end up with a single dimension array
(were MyRng a horizontal vector rather than vertical vector then you would Transpose twice to get single dimension array)Code:MyArray = Application.Transpose(MyRng.Value)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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.
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
And you can't use Join with a Variant.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Ya know, that had always puzzled me. I reckon I never got the syntax correct:
Thank you, Richard.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
Last edited by shg; 01-12-2010 at 11:56 AM.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks