J'ai essaye de la retranscrire dans une macro, mais le code ci-dessous ne fonctionne pas :
Code:
Sub Conca()
'
Dim Cell As Range
Dim Lg As Integer
Lg = 5
For Each Cell In Sheet1.Range("A5:D" & [A65489].End(xlUp).Row)
If Cell.Value <> "" Then
Sheet1.Range("F" & Cell.Row).Formula = Application.WorksheetFunction.Left(Cells(Lg, 1) & Cells(Lg, 2) & Cells(Lg, 3) & Application.WorksheetFunction.Mid(Cells(Lg, 4), 2, 1))
Lg = Lg + 1
End If
Next
End Sub
J'ai joint un petit fichier exemple pour plus de precision ^^
Re
Même si Delux semble avoir trouvé une réponse qui lui convient .
Pour strictement répondre à la question d'origine et sur la base du code fourni dans l'exemple:
VB:
Sub Conca2()
Dim Cell As Range
For Each Cell In Sheet1.Range("A5:D" & [A65489].End(xlUp).Row)
If Cell.Value <> "" Then
Sheet1.Range("F" & Cell.Row).Formula = _
"=CONCATENATE(LEFT($A" & Cell.Row & ", 1), $B" & Cell.Row & _
", $C" & Cell.Row & ", MID($D" & Cell.Row & ", 2, 1))"
End If
Next
End Sub
Pour le même résultat en "accélérant la manoeuvre":
VB:
Sub test()
With Sheet1.Range("A5.A" & [A65489].End(xlUp).Row)
.Offset(, 5).Formula = "=CONCATENATE(LEFT($A5, 1), $B5, $C5, MID($D5, 2, 1))"
.SpecialCells(xlCellTypeBlanks).Offset(, 5).ClearContents
End With
End Sub
Voir:
VB:
Sub test2()
Sheet1.Range("A5.A" & [A65489].End(xlUp).Row).SpecialCells(xlCellTypeConstants).Offset(, 5).Formula = _
"=CONCATENATE(LEFT($A5, 1), $B5, $C5, MID($D5, 2, 1))"
End Sub