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
| Sub Tansfert()
Dim lig As Integer ' déclaration ligne feuille échéancier
Dim derlig As Integer ' déclaration dernière ligne feuille relevé
Dim i As Integer ' déclaration compteur de boucle for
Dim derligECH ' déclaration dernière ligne feuille Echéancier
lig = 6 ' initialisation lig à 6
derligECH = Sheets("Echéancier").Range("a65536").End(xlUp).Row ' dernière ligne occupée de la feuille Echéancier
Sheets("Relevé").Activate ' on active la feuille Relevé
Do While lig <= derligECH 'tant que lig est inférieur ou égale à derligECH on boucle
With Sheets("Echéancier")
For i = 1 To 12
If .Cells(lig, 5 + i) = "à saisir" Then
derlig = Sheets("Relevé").Range("b65536").End(xlUp).Row + 1 ' dernière ligne occupée (évolutive) de la feuille Relevé
Cells(derlig, 2) = .Cells(lig, 1) ' copie col A feuille échéancier dans col B de feuille relevé
Cells(derlig, 3) = .Cells(lig, 2) ' copie col B feuille échéancier dans col C de feuille relevé
Cells(derlig, 4) = .Cells(lig, 3)
Cells(derlig, 5) = .Cells(lig, 4)
Cells(derlig, 6) = .Cells(lig, 5)
Cells(derlig, 1) = .Cells(lig - 1, 5 + i) ' copie date feuille échéancier dans col A de feuille relevé
.Cells(lig, 5 + i) = "saisi" ' remplace en due place "a saisir" par "saisi"
End If
Next i
End With
lig = lig + 3 ' on incrémente lig de 3 ligne
Loop
' trie descendant
Columns("A:A").Select
ActiveWorkbook.Worksheets("Relevé").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Relevé").Sort.SortFields.Add Key _
:=Range("A5:A15478"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Relevé").Sort
.SetRange Range("A4:G15478")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub |
Partager