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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
| Sub copyAct()
Dim ws As Worksheet
Dim i As Integer
'set worksheet variable
Set ws = Sheet4
With ws
.Range("DataScrapCopy01").Select
Selection.copy
.Range("AG9").Select
ActiveSheet.Paste
.Range("AI9") = WorksheetFunction.sum(Range("AC9:AE9"))
For i = 9 To .Range("AC" & Rows.Count).End(xlUp).Row
.Range("AI" & i) = WorksheetFunction.sum(Range("AC" & i & ":AE" & i))
Next i
End With
End Sub
Sub create_TCD()
'Dimension des variables
Dim wshTCD As Worksheet
Dim pvtTCD As PivotTable
'Affectation du TCD à la feuille "TCD automatique"
Set wshTCD = Worksheets("DataScrap")
On Error Resume Next
Application.ScreenUpdating = False
'Suppression de tous les TCD existants dans la feuille
For Each pvtTCD In wshTCD.PivotTables
pvtTCD.TableRange2.Clear
Next pvtTCD
'Ajout d'un TCD sur la feuille "TCD automatique"
Set pvtTCD = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Echange") _
.CreatePivotTable(tabledestination:=wshTCD.Range("AK8"), TableName:="pivo1")
'Ajout des champs au TCD
With pvtTCD
'Ajout d'une Ligne
With .PivotFields("Machine")
.Orientation = xlColumnField
.Position = 1
End With
'Ajout d'une Colonne
With .PivotFields("Shift")
.Orientation = xlRowField
.Position = 1
End With
'Ajout d'une Valeur Cotisation
With .PivotFields("Defaut")
.Orientation = xlDataField
End With
End With
ActiveSheet.PivotTables("pivo1").ColumnGrand = False
ActiveSheet.PivotTables("pivo1").RowGrand = False
wshTCD.Range("FinalEchange").Select
Selection.copy
wshTCD.Range("AW9").Select
ActiveSheet.Paste
Application.ScreenUpdating = True
'error block
On Error GoTo 0
End Sub
Sub calculScrapshift1()
Dim ws As Worksheet
Const SourceColumn As String = "AX"
Const DestColumn As String = "BA"
Const TotalCell As String = "somTotal"
Dim i As Long
Dim DernLigne As Long
Application.ScreenUpdating = False
DernLigne = Range("AX" & Rows.Count).End(xlUp).Row
On Error Resume Next
Set ws = Sheet4
With ws
For i = 9 To DernLigne
Range("BA" & i).Formula = "=(" & "AX" & i & "/" & TotalCell & ")*100"
Columns("BA").NumberFormat = "0.00"
Next i
Application.ScreenUpdating = True
End With
On Error GoTo 0
End Sub
Sub calculScrapshift2()
Dim ws As Worksheet
Const SourceColumn As String = "AY"
Const DestColumn As String = "BB"
Const TotalCell As String = "somTotal"
Dim i As Long
Dim DernLigne As Long
Application.ScreenUpdating = False
DernLigne = Range("AY" & Rows.Count).End(xlUp).Row
On Error Resume Next
Set ws = Sheet4
With ws
For i = 9 To DernLigne
Range("BB" & i).Formula = "=(" & "AY" & i & "/" & TotalCell & ")*100"
Columns("BB").NumberFormat = "0.00"
Next i
End With
Application.ScreenUpdating = True
On Error GoTo 0
End Sub
Sub calculScrapshift3()
Dim ws As Worksheet
Const SourceColumn As String = "AZ"
Const DestColumn As String = "BC"
Const TotalCell As String = "somTotal"
Dim i As Long
Dim DernLigne As Long
Application.ScreenUpdating = False
DernLigne = Range("AZ" & Rows.Count).End(xlUp).Row
On Error Resume Next
Set ws = Sheet4
With ws
For i = 9 To DernLigne
Range("BC" & i).Formula = "=(" & "AZ" & i & "/" & TotalCell & ")*100"
Columns("BC").NumberFormat = "0.00"
Next i
Application.ScreenUpdating = True
End With
On Error GoTo 0
End Sub
Sub somTotalScrap()
Dim ws As Worksheet
Dim i As Integer
Dim derli As Long
' sheet variable
Set ws = Sheet4
With ws
Application.ScreenUpdating = False
Range("BD9") = WorksheetFunction.sum(Range("BA9:BC9"))
For i = 9 To Range("BA" & Rows.Count).End(xlUp).Row
Range("BD" & i) = WorksheetFunction.sum(Range("BA" & i & ":BC" & i))
Next i
Application.ScreenUpdating = True
End With
End Sub
Sub MaxScrap()
On Error Resume Next
Application.ScreenUpdating = False
Range("AW8:BE38").Select
ActiveWorkbook.Worksheets("DataScrap").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DataScrap").Sort.SortFields.Add Key:=Range( _
"BD9:BD38"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("DataScrap").Sort
.SetRange Range("AW8:BE38")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
On Error GoTo 0
End Sub
Sub calculatCumuleScrap()
On Error Resume Next
Dim ws As Worksheet
Dim VisRng As Range, c As Range
Dim StartRow As Long
Dim LastRow As Long
Set ws = Sheet4
With ws
Application.ScreenUpdating = False
LastRow = .Cells(.Rows.Count, "BD").End(xlUp).Row '<-- get last row with data in Column K
StartRow = 9 '<-- init value
' set visible range to only filtered cells in Column G
Set VisRng = .Range(Range("BD" & StartRow), Range("BD" & LastRow)).SpecialCells(xlCellTypeVisible)
StartRow = VisRng.Item(1).Row '<-- update first row in visible range
For Each c In VisRng
If c.Row = StartRow Then
.Range("BE" & c.Row) = .Range("BD" & c.Row).Value
Else
.Range("BE" & c.Row).Formula = "=SUBTOTAL(9,BD" & StartRow & ":BD" & c.Row & ")"
End If
Next c
.Columns("BE").NumberFormat = "0.00"
Application.ScreenUpdating = True
End With
On Error GoTo 0
End Sub
Sub copyScrapFinal()
'error handler
On Error Resume Next
Application.ScreenUpdating = False
Sheet4.Activate
Range("graphiq,graphiqu,grafiquu").Select
Selection.copy
Range("BG9").Select
ActiveSheet.Paste
Application.ScreenUpdating = True
'error block
On Error GoTo 0
End Sub |
Partager