code concatenation deux colonnes

fredoalex

XLDnaute Nouveau
Bonjour à tous, je souhaite faire une concatenation des deux colonnes mais je n y arrives pas. Voici mon code ainsi que mon fichier ci joint


Sub aller()
Dim colonne As Variant, ligne As Variant, colonnea As Variant, ligneb As Variant
Dim nb_ligne As Variant, y As Variant, z As Variant, nb_ligne2 As Variant, nb_ligne3 As Variant
Dim a As Variant, d As Variant, c As Variant

colonne = Range("B3").Column
ligne = Range("B3").Row
colonnea = Range("d3").Column
ligneb = Range("d3").Row
nb_ligne = WorksheetFunction.CountA(Range("B:B"))
nb_ligne2 = WorksheetFunction.CountA(Range("D:D"))

nb_ligne3 = nb_ligne + nb_ligne2

MsgBox nb_ligne3



For y = 4 To nb_ligne + 2
a = Sheets("feuil1").Cells(y, colonne).Value
MsgBox a

Next
For z = 4 To nb_ligne2 + 2
d = Sheets("feuil1").Cells(z, colonnea).Value
MsgBox b
Next



For c = 3 To nb_ligne3
Rows(c, 7) = a & d
Next
 

Pièces jointes

  • Classeur1.xlsm
    17.2 KB · Affichages: 43
  • Classeur1.xlsm
    17.2 KB · Affichages: 43
  • Classeur1.xlsm
    17.2 KB · Affichages: 50

pierrejean

XLDnaute Barbatruc
Re : code concatenation deux colonnes

bonjour fredoalex

a tester:

Code:
Sub test()
n = Range("B" & Rows.Count).End(xlUp).Row
m = Range("D" & Rows.Count).End(xlUp).Row
If n > m Then
  p = n
Else
  p = m
End If
For n = 4 To p
 Range("G" & n) = Trim(Range("B" & n) & " " & Range("D" & n))
Next
End Sub
 

steven02880

XLDnaute Nouveau
Re : code concatenation deux colonnes

Bonjour,

Tu as fait quelques erreurs dans ton code, essayes celui là.



Code:
Sub aller()
Dim colonne As Variant, ligne As Variant, colonnea As Variant, ligneb As Variant
Dim nb_ligne As Variant, y As Variant, z As Variant, nb_ligne2 As Variant, nb_ligne3 As Variant
Dim a As Variant, d As Variant, c As Variant
c = 3
colonne = Range("B3").Column
ligne = Range("B3").Row
colonnea = Range("d3").Column
ligneb = Range("d3").Row
nb_ligne = WorksheetFunction.CountA(Range("B:B"))
nb_ligne2 = WorksheetFunction.CountA(Range("D:D"))
nb_ligne3 = nb_ligne + nb_ligne2

For y = 4 To nb_ligne + 2
For z = 4 To nb_ligne2 + 2
c = c + 1
a = Worksheets("Feuil1").Cells(y, colonne).Value
d = Worksheets("Feuil1").Cells(z, colonnea).Value
Cells(c, 7) = a & d
Next z
Next y

End Sub

Si tu as un soucis n'hésites pas à le dire.

Steven
 

steven02880

XLDnaute Nouveau
Re : code concatenation deux colonnes

Chez moi, ma macro donne ce que tu souhaites.

Je sais pas si tu as testé, mais lances la macro de ce fichier là. Tu verras le résultat.

Si ce n'est toujours pas bon, peut tu me donner un exemple de ce que tu souhaites obtenir je pourrais peut être mieux t'aider du coup.

Steven
 

Pièces jointes

  • fredoalex.xlsm
    16.8 KB · Affichages: 37

pierrejean

XLDnaute Barbatruc
Re : code concatenation deux colonnes

Re

Avec une bonne explication cela va un peu mieux

Code:
Sub test()
n = Range("B" & Rows.Count).End(xlUp).Row
m = Range("D" & Rows.Count).End(xlUp).Row
ligne = 4
For z = 4 To n
 For zz = 4 To m
  Range("G" & ligne) = Trim(Range("B" & z) & " " & Range("D" & zz))
  ligne = ligne + 1
 Next
Next
End Sub
 

Discussions similaires

Réponses
12
Affichages
247

Statistiques des forums

Discussions
312 196
Messages
2 086 095
Membres
103 116
dernier inscrit
kutobi87