Appiattiamo i Range!

Option Explicit

Function flatten(ByVal r As Range, Optional delimiter As String = "", _
Optional bycol As Boolean = False) As String
'appiattisce un range riga per riga e restituisce una stringa
'(solo celle non vuote) ' si può specificare un delimitatore tra i
'diversi valori e se si specifica "bycol:=True", l'appiattimento è
'effettuato colonna per colonna

Dim vect() As Variant, v As Variant, i As Integer, s As String
Dim col As Range
    
    If bycol Then
        If r.Rows.Count = 1 Then
            flatten = flatten(r, delimiter, False)
            Exit Function
        End If
        s = ""
        For Each col In r.Columns
            s = s & Join(Application.Transpose(col), delimiter)
        Next
        flatten = s
    Else
        ReDim vect(0 To r.Cells.Count - 1)
        For Each v In r.Cells
            vect(i) = v
            i = i + 1
        Next
    
        flatten = Join(vect, delimiter)
    End If
End Function

posted @ domenica 15 marzo 2015 18:55

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 3 and 7 and type the answer here:
 

Live Comment Preview: