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
| Private Sub Worksheet_selectionchange(ByVal Target As Range)
If worksheets("Rajouts Données").Cells(20, 20).Value = 1 Then
Range("K5").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-0]C[-1]="""","""",LEFT(R[-0]C[-1],6))"
End If
End Sub
Je dois donc écrire le code suivant pour chaque ligne :
Private Sub Worksheet_selectionchange(ByVal Target As Range)
If worksheets("Rajouts Données").Cells(20, 20).Value = 1 Then
Range("K5").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-0]C[-1]="""","""",LEFT(R[-0]C[-1],6))"
If worksheets("Rajouts Données").Cells(21, 20).Value = 1 Then
Range("K6").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-0]C[-1]="""","""",LEFT(R[-0]C[-1],6))"
If worksheets("Rajouts Données").Cells(22, 20).Value = 1 Then
Range("K7").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-0]C[-1]="""","""",LEFT(R[-0]C[-1],6))"
.../...
If worksheets("Rajouts Données").Cells(20+N-1, 20).Value = 1 Then
Range("K" & 5+N-1).Select
ActiveCell.FormulaR1C1 = _
"=IF(R[-0]C[-1]="""","""",LEFT(R[-0]C[-1],6))"
' N= nombre de boucle
End If
End Sub |
Partager