Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Modifier macro - Range au lieu de Active Cell

2 réponses
Avatar
Christophe
Bonjour:

J'ai trouv=E9 une macro qui permet de trier par ordre alphabetiques les
mots-chaines de caract=E8res s=E9par=E9s par des virgules =E0 l'int=E9rieur
d'une cellule. Cette macro prend en compte la cellule active.
J'aimerais pouvoir la modifier afin q"'elle agisse sur la plage de
cellules Range("AE2:AE" & [AE2].End(xlDown).Row)

Merci par avance de votre aide.

Christophe

Sub TriCellule()
'
' TriCellule Macro
' La fonction Split transforme une cha=EEne en tableau
' La fonction Join fait l'inverse
'
Dim Chn As String, Tri As Boolean, I As Integer, Tmp As String
Chn =3D ActiveCell.Text
If Chn =3D "" Then Exit Sub
TbChn =3D Split(Chn, ",")
If UBound(TbChn) > 0 Then
Do
Tri =3D False
For I =3D 1 To UBound(TbChn)
If TbChn(I) < TbChn(I - 1) Then
Tmp =3D TbChn(I - 1)
TbChn(I - 1) =3D TbChn(I)
TbChn(I) =3D Tmp
Tri =3D True
End If
Next
Loop While Tri =3D True
Chn =3D Join(TbChn, ",")
ActiveCell.Value =3D Chn
End If
'
End Sub

2 réponses

Avatar
JB
Bonjour,

Sub TriChamp()
For Each c In Range("AE2:AE" & [AE2].End(xlDown).Row)
temp = Split(c, ",")
For I = LBound(temp) To UBound(temp)
For j = I To UBound(temp)
If temp(j) < temp(I) Then
tempo = temp(j)
temp(j) = temp(I)
temp(I) = tempo
End If
Next j
Next I
c.Value = Join(temp, ",")
Next c
End Sub

JB


On 9 avr, 10:33, Christophe wrote:
Bonjour:

J'ai trouvé une macro qui permet de trier par ordre alphabetiques les
mots-chaines de caractères séparés par des virgules à l'intérieu r
d'une cellule.  Cette macro prend en compte la cellule active.
J'aimerais pouvoir la modifier afin q"'elle agisse sur la plage de
cellules Range("AE2:AE" & [AE2].End(xlDown).Row)

Merci par avance de votre aide.

Christophe

Sub TriCellule()
'
' TriCellule Macro
' La fonction Split transforme une chaîne en tableau
' La fonction Join fait l'inverse
'
Dim Chn As String, Tri As Boolean, I As Integer, Tmp As String
Chn = ActiveCell.Text
If Chn = "" Then Exit Sub
TbChn = Split(Chn, ",")
If UBound(TbChn) > 0 Then
Do
Tri = False
For I = 1 To UBound(TbChn)
If TbChn(I) < TbChn(I - 1) Then
Tmp = TbChn(I - 1)
TbChn(I - 1) = TbChn(I)
TbChn(I) = Tmp
Tri = True
End If
Next
Loop While Tri = True
Chn = Join(TbChn, ",")
ActiveCell.Value = Chn
End If
'
End Sub


Avatar
Christophe
Bonjour JP:

Très fort. Merci.

Christophe