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
| Sub Feuilles()
Dim feuille As Worksheet
Application.ScreenUpdating = False 'Interdit l'affichage pour gagner du temps d'exécution
For Each feuille In Worksheets
If Not feuille.Name = "Commun" Then feuille.Select: Ref_Interne: Invoice: Decalage
Next
Application.ScreenUpdating = True 'Réinitialise l'affichage
End Sub
Sub Ref_Interne()
Dim plage As Range
Dim cel As Range
Dim x As Integer
'copie de l'étiquette de colonne
For x = 12 To 14
Cells(1, x) = Cells(1, 11)
Next
'la variable plage couvre la matrice partant de la cellule(ligne2, colonne11) à _
depuis la dernière cellule de la feuille on simule l'appui des touches Ctrl flèche vers le haut _
ainsi on est sûr d'être sur la dernière cellule de la colonne contenant une donnée.
Set plage = Range(Cells(2, 11), Cells(Rows.Count, 11).End(xlUp))
' la boucle For Next parcourt chaque cellule
For Each cel In plage
'la valeur de la cellule décalée de 3 colonnes devient la partie droite de la cellule d'origine _
sur sa longueur - 6 (CDS : )= 6 caractères
cel.Offset(0, 1) = Right(cel, Len(cel) - 6)
Next
'on utilise le filtre élaboré pour copier sans doublons
Range("L1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range _
("M1:M2"), CopyToRange:=Columns("N:N"), Unique:=True
'tri ce la colonne N
Range("N2").Select
Range(Selection, Selection.End(xlDown)).Select
VerifNum
Selection.Sort Key1:=Range("N2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'on efface les colonnes intermédiaires
Range("L:L,M:M").Clear
End Sub
Sub Invoice()
Dim cel As Range
onglet = ActiveSheet.Name
Sheets("Commun").Select
'on utilise le filtre élaboré pour copier sans doublons
Range("M3") = Range("C3")
Range("L3") = Range("H3")
Range("L4") = onglet
Range(Cells(3, 3), Cells(Rows.Count, 8).End(xlUp)).Select
Selection.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range _
("L3:L4"), CopyToRange:=Range("M3"), Unique:=True
Range("M4").Select
Range(Selection, Selection.End(xlDown)).Select
VerifNum
Selection.Sort Key1:=Range("M4"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.Copy Destination:=Worksheets(onglet).Range("P2")
Range("K:M").Clear
Sheets(onglet).Select
End Sub
Sub VerifNum()
Dim cel2 As Range
For Each cel2 In Selection
If IsNumeric(cel2) Then cel2 = CLng(cel2)
Next
End Sub
Sub Decalage()
Dim plage As Range
Dim cel As Range
Dim x As Integer
Set plage = Range(Cells(2, 14), Cells(Rows.Count, 14).End(xlUp))
For Each cel In plage
If cel.Offset(0, 2) - cel <> 0 Then
cel.Activate
cel.Insert Shift:=xlDown
cel.Offset(-1, 1) = cel.Offset(-1, 0) - cel.Offset(-1, 2)
End If
Next
End Sub |
Partager