Función Concatenar rango

roberto

New Member
Joined
Aug 28, 2002
Messages
43
Encontre esta función en la pagina:
http://www.danielklann.com/excel/user_defined_functions.htm
pero no hace lo que deberia de hacer, alguien podría ayudarme a corregirla?


Public Function ConcatenateRange(Separator As String, ParamArray ConcatRange() As Variant)
Dim vItem As Variant, rngCell As Range
Dim strSep As String
Dim vRetVal As Variant

For Each vItem In ConcatRange

For Each rngCell In vItem.Cells

vRetVal = vRetVal & rngCell.Value & strSep

Next rngCell

Next vItem

ConcatenateRange = Left$(vRetVal, Len(vRetVal))

End Function
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hola Roberto,

En vez de corregir esa otra, le ofrezco la siguiente que agarré de aquí en Mr. Excel, ni me acuerdo en cual "hilo". Pero me parece más robusto porque uno puede usarlo como un UDF en una celula de Excel, o llamarla de VBA con un Array de valores.

<font face=Courier New>
<SPAN style="color:#007F00">'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯</SPAN>
<SPAN style="color:#00007F">Function</SPAN> AConcat(varA <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN>, <SPAN style="color:#00007F">Optional</SPAN> strSep <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> = "") <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#007F00">'______________________________________________________________________________</SPAN>

<SPAN style="color:#007F00">' by Harlan Grove, March 2002</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> varY <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN>
    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">TypeOf</SPAN> varA <SPAN style="color:#00007F">Is</SPAN> Range <SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> varY <SPAN style="color:#00007F">In</SPAN> varA.Cells
            AConcat = AConcat & varY.Value & strSep
        <SPAN style="color:#00007F">Next</SPAN> varY
    <SPAN style="color:#00007F">ElseIf</SPAN> IsArray(varA) <SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> varY <SPAN style="color:#00007F">In</SPAN> varA
            AConcat = AConcat & varY & strSep
        <SPAN style="color:#00007F">Next</SPAN> varY
    <SPAN style="color:#00007F">Else</SPAN>
        AConcat = AConcat & varA & strSep
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    AConcat = Left(AConcat, Len(AConcat) - Len(strSep))
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,226,735
Messages
6,192,733
Members
453,752
Latest member
Austin2222

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top