Sub SuperposerItemsChaine()
Dim cel As Range, c As Range
Application.ScreenUpdating = False
For Each cel In Selection
cel = Application.WorksheetFunction.Trim(cel) 'suppression de tous les éventuels espaces superflus de la chaîne
With CreateObject("VBScript.RegExp")
.Pattern = "( )([A-ZÀ-Ÿ])" 'un espace suivi d'une lettre majuscule. Tient compte des majuscules diacritées
.IgnoreCase = False
.Global = True
For Each c In cel
c.Value = .Replace(c.Value, "$1" & Chr(10) & "$2")
Next
End With
Next
[C2500].Select: Application.ScreenUpdating = True
End Sub
Sub Copier_Coller()
[Source].Offset(7) = [Source].Value
End Sub
Sub SuperposerItemsChaine()
Dim majuscules$, c As Range, t$, i%
majuscules = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÌÍÎÏÙÚÛÜÑÇ"
Application.ScreenUpdating = False
For Each c In Selection
t = " " & Application.Trim(Replace(c, vbLf, " "))
For i = Len(t) To 2 Step -1
If InStr(majuscules, Mid(t, i, 1)) And Mid(t, i - 1, 1) = " " Then t = Left(t, i - 2) & vbLf & Mid(t, i): i = i - 1
Next i
c = Mid(t, 2)
Next c
[C2500].Select
End Sub
With CreateObject("VBScript.RegExp")
Sub Copier_Coller()
[Source].Offset(7) = [Source].Value
End Sub
Sub SuperposerItemsChaine()
Dim cel As Range, c As Range
Application.ScreenUpdating = False
For Each cel In Selection
cel = Application.WorksheetFunction.Trim(cel) 'suppression de tous les éventuels espaces superflus de la chaîne
With CreateObject("VBScript.RegExp")
.Pattern = "( )([A-Z]|[ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÌÍÎÏÙÚÛÜÑÇ])" 'un espace suivi d'une lettre majuscule. Tient compte des majuscules diacritées
.IgnoreCase = False
.Global = True
For Each c In cel
c.Value = .Replace(c.Value, "$1" & vbLf & "$2")
Next
End With
Next
[C2500].Select
End Sub
Sub Copier_Coller()
[Source].Offset(7) = [Source].Value
With [Source].Offset(7).Resize([Source].Rows.Count)
.AutoFill .Resize(1000 * .Rows.Count)
End With
End Sub
Sub SuperposerItemsChaine_Avec_RegExp()
Dim dur, o As Object, tablo, i&, t$
dur = Timer
Set o = CreateObject("VBScript.RegExp")
o.IgnoreCase = False
o.Global = True
o.Pattern = "( )([A-Z]|[ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÌÍÎÏÙÚÛÜÑÇ])" 'un espace suivi d'une lettre majuscule. Tient compte des majuscules diacritées
With [Source].Offset(7).Resize(1000 * [Source].Rows.Count)
tablo = .Value 'matrice, plus rapide
For i = 1 To UBound(tablo)
t = Application.Trim(Replace(tablo(i, 1), vbLf, " "))
tablo(i, 1) = o.Replace(t, "$1" & vbLf & "$2")
Next
.Value = tablo
End With
MsgBox "Durée " & Format(Timer - dur, "0.00 \sec")
End Sub
Sub SuperposerItemsChaine_Sans_RegExp()
Dim dur, majuscules$, tablo, i&, t$, j%
dur = Timer
majuscules = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÌÍÎÏÙÚÛÜÑÇ"
With [Source].Offset(7).Resize(1000 * [Source].Rows.Count)
tablo = .Value 'matrice, plus rapide
For i = 1 To UBound(tablo)
t = " " & Application.Trim(Replace(tablo(i, 1), vbLf, " "))
For j = Len(t) To 2 Step -1
If InStr(majuscules, Mid(t, j, 1)) And Mid(t, j - 1, 1) = " " Then t = Left(t, j - 2) & vbLf & Mid(t, j): j = j - 1
Next j
tablo(i, 1) = Mid(t, 2)
Next i
.Value = tablo
End With
MsgBox "Durée " & Format(Timer - dur, "0.00 \sec")
End Sub
Sub SuperposerItemsChaine()
Dim cel As Range, c As Range
Application.ScreenUpdating = False
For Each cel In Selection
cel = Application.WorksheetFunction.Trim(cel) 'suppression de tous les éventuels espaces superflus de la chaîne
With CreateObject("VBScript.RegExp")
.Pattern = "( )([A-ZÀ-Ý])" 'un espace suivi d'une lettre majuscule. Tient compte des majuscules diacritées
.IgnoreCase = False
.Global = True
For Each c In cel
c.Value = .Replace(c.Value, "$1" & Chr(10) & "$2")
Next
End With
Next
[C2500].Select: Application.ScreenUpdating = True
End Sub
Elles ne sont pas lentes si l'objet n'est créé qu'une fois, voir le post #10.En revanche, il est intéressant de constater à quel point les RegExp sont lentes.