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
| Sub Mise_en_forme()
'
' Mise_en_forme Macro
'
'définition des variables
Dim nblignes As Integer
Dim lig_dr As Integer
Dim nom_dr As String
Dim rep_trav As String
Dim rep As String
'désactive les opérations à l'écran
Application.ScreenUpdating = False
'sélectionne la cellule A1
Range("a1").Select
'Calcule le nombre de lignes
Do While Not (IsEmpty(ActiveCell))
nblignes = nblignes + 1
Selection.Offset(1, 0).Select
Loop
'Sélectionne les deux premières colonnes
Columns("A:B").Select
'insère deux colonnes en début de fichier
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
'se place en A2
Range("A2").Select
'affiche le libellé de la DR
ActiveCell.FormulaR1C1 = "=VLOOKUP(LEFT(RC[2],3),DR,2)"
'se place en b2
Range("B2").Select
'affiche le mercure seul
ActiveCell.FormulaR1C1 = "=VALUE(RIGHT(RC[1],LEN(RC[1])-3))"
'sélectionne les cellules a2 et b2
Range("A2:B2").Select
'recopie incrémentée jusqu'à la fin de fichier
Selection.AutoFill Destination:=Range("A2:B" & nblignes)
'sélectionne la plage de cellules recopiées
Range("A2:B" & nblignes).Select
'effectue un copier/collage spécial valeurs en b2
Selection.Copy
Range("B2").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
IconFileName:=False
'supprime la colonne a
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
'met le texte "Base" en a1
Range("A1").Select
ActiveCell.FormulaR1C1 = "Base"
ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range( _
"A2:A" & nblignes), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Fichier").Sort
.SetRange Range("A1:D" & nblignes)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2").Select
'réactive les opérations à l'écran
Application.ScreenUpdating = True
'sélectionne la cellule A2
Range("a2").Select
nom_dr = ActiveCell.Value
lig_dr = ActiveCell.Row
'travaille jusqu'à la fin de fichier
Do While Not (IsEmpty(ActiveCell))
'tant que le nom de la DR est celui de la celluel active
Do While ActiveCell.Value = nom_dr
lig_dr = lig_dr + 1
Selection.Offset(1, 0).Select
Loop
Range("B1:D" & lig_dr - 1).Select
'Exit Sub
Range("a2").Select
nom_dr = ActiveCell.Value
nomfichier = nom_dr & ".csv"
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
ChDir "C:\Users\Public\Documents\MAJ TLC 2007"
ActiveWorkbook.SaveAs Filename:="C:\Users\Public\Documents\MAJ TLC 2007\" & nomfichier, FileFormat:=xlCSV, _
CreateBackup:=False
Loop
'Sheets("Création fichiers").Select
'Range("A1").Select
'Application.Run Sheets("Création fichiers").Range("XFD1")
End Sub |
Partager