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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| Option Explicit
Sub copier()
Dim WSSource As Worksheet
Dim WSDest As Worksheet
Dim i As Integer
Dim j As Boolean
Dim ligne_début As String
Dim ligne_fin As String
Dim ligne As Integer
Dim cell As String
'Demander le numéro de la ligne de début
ligne_début = InputBox("Placer : Ligne début ?")
'Test de réponse exacte
j = False
Do While j = False
j = True
Do Until IsNumeric(ligne_début)
ligne_début = InputBox("N'importe quoi! Il faut donner un numéro de ligne!!!")
j = False
Loop
If ligne_début < 15 Then
ligne_début = InputBox("Qu'est ce que tu crois?? La ligne 0 n'existe pas!")
j = False
End If
Loop
'Demander le numéro de ligne de fin
ligne_fin = InputBox("Placer : Ligne fin ?")
'Test de réponse exacte
j = False
Do While j = False
j = True
Do Until IsNumeric(ligne_fin)
ligne_fin = InputBox("N'importe quoi! Il faut donner un numéro de ligne!!!")
j = False
Loop
If ligne_fin <= ligne_début Then
ligne_fin = InputBox("Qu'est ce que tu crois?? La ligne 0 n'existe pas!")
j = False
End If
Loop
If ligne_début = 0 Then
ligne_début = InputBox("Qu'est ce que tu crois?? La ligne 0 n'existe pas!")
End If
Set WSSource = Workbooks("ruitz.xls").Worksheets("planning")
Set WSDest = Workbooks("planning.csv").Worksheets("planning")
'Boucle pour chaque ligne
For ligne = ligne_début To ligne_fin
'cherche la ligne vide dans le classeur de destination
i = WSDest.Range("A65536").End(xlUp).Row + 1
'On copie les cellules E,ligne, K ligne et Nligne ->Q ligne
WSSource.Cells(ligne, 5).Copy (WSDest.Cells(i, 1))
WSSource.Cells(ligne, 11).Copy (WSDest.Cells(i, 2))
WSSource.Cells(ligne, 14).Copy (WSDest.Cells(i, 3))
WSSource.Cells(ligne, 15).Copy (WSDest.Cells(i, 4))
WSSource.Cells(ligne, 16).Copy (WSDest.Cells(i, 5))
cell = Cells(i, 21).Address
WSSource.Cells(ligne, 17).Copy
WSDest.Range(cell).PasteSpecial Paste:=xlValues, Operation:=xlNone
Next
End Sub |
Partager