Bonjour

Je fais appel à votre champs de connaissances infinies du VBA . Cf:le tableau ci dessous:

Nom : copie_xls.png
Affichages : 274
Taille : 9,1 Ko



je dois réaliser une concaténation de données de la colonne2 dans la colonne 3 en fonction du nombre de lignes que comporte la case colonne 1 (exemple:
la case A (colonne1) comporte 4 lignes de données (colonne2) que je concatène dans la 1ere ligne de la colonne3.
Sachant que les plages à concaténer sont variables. J'ai écris la routine qui fonctionne mais qui me semble assez
lourde (je reproduis la concaténation en la répétant pour chaque ajout de ligne a concaténer, j'en ai fait 8 maximum, et j'ai
des cases colonnes2 de 25 lignes à concaténer. Comment puis-je itérer la concaténation sans avoir à l'ajouter explicitement
à chaque fois?
D'avance, merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
41
42
43
44
45
46
47
48
49
50
Sub concaten_1()
 
Dim i As Long
 
Range("A22") = "this is the end my friend"
 
 
Do
i = i + 1
 
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" And Cells(i, 1).Offset(4, 0).Value = "" And Cells(i, 1).Offset(5, 0).Value = "" And Cells(i, 1).Offset(6, 0).Value = "" And Cells(i, 1).Offset(7, 0).Value = "" And Cells(i, 1).Offset(8, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1]&""   /   ""&R[4]C[-1]&""   /   ""&R[5]C[-1]&""   /   ""&R[6]C[-1]&""   /   ""&R[7]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" And Cells(i, 1).Offset(4, 0).Value = "" And Cells(i, 1).Offset(5, 0).Value = "" And Cells(i, 1).Offset(6, 0).Value = "" And Cells(i, 1).Offset(7, 0).Value = "" And Cells(i, 1).Offset(8, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1]&""   /   ""&R[4]C[-1]&""   /   ""&R[5]C[-1]&""   /   ""&R[6]C[-1]&""   /   ""&R[7]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" And Cells(i, 1).Offset(4, 0).Value = "" And Cells(i, 1).Offset(5, 0).Value = "" And Cells(i, 1).Offset(6, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1]&""   /   ""&R[4]C[-1]&""   /   ""&R[5]C[-1]&""   /   ""&R[6]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" And Cells(i, 1).Offset(4, 0).Value = "" And Cells(i, 1).Offset(5, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1]&""   /   ""&R[4]C[-1]&""   /   ""&R[5]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" And Cells(i, 1).Offset(4, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1]&""   /   ""&R[4]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" And Cells(i, 1).Offset(3, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1]&""   /   ""&R[3]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" And Cells(i, 1).Offset(2, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1]&""   /   ""&R[2]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value = "" Then
Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1]&""   /   ""&R[1]C[-1])"
Else
If Cells(i, 1).Value <> "" And Cells(i, 1).Offset(1, 0).Value <> "" Then Cells(i, 3).FormulaR1C1 = "=CONCATENATE(RC[-1])"
 
 
 
End If
End If
End If
End If
End If
End If
End If
End If
Loop Until Cells(i, 1).Value = "this is the end my friend"
 
 
End Sub