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
|
Sub Macro13()
' Date du jour (format à l'anglaise : aaaa-m-j)
Dim DateJourUS As String
DateJourUS = Format(Now, "yyyy mm dd")
Dim Wb As Workbook
Dim CellSN As Range
Dim Lastline As Variant
Set Wb = ActiveWorkbook
'
' Application.ScreenUpdating = False pour empecher de voir defiler les ouvertures des feuilles Excel ( ne pas oublier de le remettre sur TRUE en fin de programme
Application.ScreenUpdating = False
'Application.DisplayAlerts = False
'
' Pour Deboggage pas-à-pas : utiliser F9 pour ajouter quelques points d'arret
'
'
' Ouvrir la feuille "Fichier.xlsx"
'
Workbooks.Open Filename:= _
Wb.Path & "\Fichier.xlsx"
Sheets("Feuille1").Select
'
' Suppression 1ere ligne vide
'
Rows("1:1").Select
Selection.Delete Shift:=xlUp
'
' Suppression 1ere colonne vide
'
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
'
' Mise en forme de la feuille entiere avec Ajustement de toutes les colonnes
'
Cells.Select
Selection.Columns.AutoFit
'
' Mise ne forme de la feuille entiere avec Figeage de la 1ere Ligne
'
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
'Selection.AutoFilter
'
' Compter le nombre de lignes ( = LASTLINE )
'
Sheets("Feuille1").Select
Range("B2").Select
Lastline = Range("B2").End(xlDown).Row
MsgBox " LASTLINE = " & Lastline
'
' Tri sur SERIAL NUMBER puis sur la LAST NAME
'
ActiveWorkbook.Worksheets("Feuille1").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("Feuille1").Sort.SortFields. _
Add Key:=Range("B:B"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortTextAsNumbers
ActiveWorkbook.Worksheets("Feuille1").Sort.SortFields. _
Add Key:=Range("AE:AE"), SortOn:=xlSortOnValues, Order:=xlAscending _
, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Feuille1").Sort
.SetRange Range("A:AL")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
'
' Ajout d'une colonne 'ANOMALIE' dans premiere colonne
'
Sheets("Feuille1").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1:AL1").Select
ActiveCell.FormulaR1C1 = "Anomalie"
Selection.Interior.ColorIndex = 47
Selection.Font.ColorIndex = 2
Selection.Font.Bold = True
Columns("A:A").Select
Selection.ColumnWidth = 12
Selection.Font.Size = 9
Selection.HorizontalAlignment = xlCenter
'
'
Sheets("Feuille1").Select
For Each CellSN In Range("C2:C" & Lastline)
'
' Signalement des Champs avec Espace au debut ou à la fin
' Cherche les CI Nmae = avec quelques espaces ( colonne 2 ou Colonne B )
Signalement (-1)
' Cherche les SN = avec quelques espaces ( colonne 3 ou Colonne C )
Signalement (0)
' Cherche les Tag Number = avec quelques espaces ( colonne 4 ou Colonne D )
Signalement (1)
' Cherche les Product Categorisation Tier 1 = avec quelques espaces ( colonne 5 ou Colonne E )
Signalement (2)
....
End Sub
Sub Signalement(Pos As Integer)
' Signalement des Champs avec Espace au debut ou à la fin
If CellSN.Offset(, Pos) Like " *" Or CellSN.Offset(, Pos) Like "* " Then '<=== ICI le message d'erreur avec code = 424 object requis
CellSN.Offset(, Pos).AddComment
CellSN.Offset(, Pos).Comment.Text Text:="Attention il y a un espace " & Chr(10) _
& "au debut du champ ou à la fin du champ !"
CellSN.Offset(, Pos).Interior.ColorIndex = 6
CellSN.Offset(, -2).Value = "Espace"
End If
End Sub |
Partager