1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Public Function DecoupeChaine(ByVal chaine As Variant, _
ByVal sep As String, _
ByVal numero As Variant, _
Optional ByVal blnValue As Boolean = True, _
Optional ByVal blnRecursive As Boolean = False) As String
Dim t() As String
Dim i As Integer
If Not blnRecursive Then
If IsNumeric(numero) Then
If blnValue Then
If numero <> -1 Then
DecoupeChaine = Split(Trim(chaine), sep)(numero - 1)
Else
DecoupeChaine = Split(Trim(chaine), sep)(UBound(Split(Trim(chaine), sep)))
End If
Else
DecoupeChaine = Split(Range(chaine.Address).FormulaLocal, sep)(numero - 1)
End If
ElseIf Right(numero, 2) = "--" Then
numero = CInt(Left(numero, Len(numero) - 2))
t = Split(chaine, sep)
For i = numero - 1 To UBound(t)
DecoupeChaine = DecoupeChaine & sep & t(i)
Next i
DecoupeChaine = Mid(DecoupeChaine, Len(sep) + 1)
ElseIf Left(numero, 2) = "--" Then
numero = CInt(Right(numero, Len(numero) - 2))
t = Split(chaine, sep)
For i = 0 To numero - 1
DecoupeChaine = DecoupeChaine & sep & t(i)
Next i
DecoupeChaine = Mid(DecoupeChaine, Len(sep) + 1)
End If
Else
DecoupeChaine = Split(chaine, sep)(numero - 1)
End If
End Function |
Partager