Comment append des espaces entre des lignes de text qui ne sont pas identiques

Je search un moyen d'append des espaces entre les lignes. La seule fois où je souhaite append un espace, c'est lorsque le text n'est pas identique à celui de la ligne ci-dessus. J'ai des problèmes et je ne peux pas le comprendre. Voici ce que j'ai obtenu jusqu'ici:

Sub Spaces() Dim cell As Range Dim Text1 As Ssortingng Dim Text2 As Ssortingng For Each cell In Selection Text1 = Cells(cell, 1).Text Text2 = Cells(cell - 1, 1).Text If InStr(1, cell, "-", 1) Then If Cells(cell, 1) <> Cells(cell - 1, 1) Then Else: Cells(cell + 1, 1).EntireRow.Insert End If End If Next End Sub 

Tout un indice sur l'endroit où je me trompe serait très apprécié.

C'est le code que j'ai utilisé pour séparer les lignes qui tenaient différentes tailles de tubes.

 Sub blastListSort() Range("A1").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _ Cells.Find(What:="*", SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select For rown = Selection.Rows.Count To 2 Step -1 Size = Cells(rown, 3).Value Size2 = Cells(rown, 3).Offset(-1).Value lastRow = Range("A" & Rows.Count).End(xlUp).Row If Size2 <> Size Then Cells(rown, 6).EntireRow.Select Cells(rown, 6).EntireRow.Insert End If Next End Sub 

J'espère que cela aide! 🙂

Sans trop changer, vous pouvez essayer quelque chose comme ceci:

 Sub Spaces() Dim cell As Range Dim Text1 As Ssortingng Dim Text2 As Ssortingng For Each cell In Selection ' initialize first ssortingng Text1 = cell.Text ' initialize second ssortingng for first time through If Text2 = vbNullSsortingng Then Text2 = Text1 ' perform test If InStr(1, Text1, "-", 1) Then If Text1 <> Text2 Then ' insert row cell.EntireRow.Insert End If End If ' set second ssortingng for next time through loop Text2 = Text1 Next End Sub