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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
| Sub BilanHeures()
'Pour chaque intervenant (1 colonne par intervenant)
'En fonction de l'année
'On ouvre le fichier Pointage correspondant à l'intervenant et à l'année
'Pour chaque semaine du tableau récpa d'heures on cherche le n°CI dans la bonne feuille et dans la bonne zone
'Si on trouve le n° de CI, on inscrit dans le tableau récap le nb d'heures semaines
Dim appxl As Excel.Application
Dim Fichier As Window
Dim feuille As Worksheet
Set appxl = CreateObject("Excel.application")
Dim FichierAouvrir As String
Dim NoCI As String
Dim Intervenant As String
Dim Initiale As String
Dim Ligne As Integer
Dim Année As Integer
Dim Année0 As Integer
Dim i As Integer
Dim j As Integer
Dim NoColonne As Integer
Dim DernLigne As Long
Dim FichierXL As String
Dim CheminFichierXL As String
Dim NoSem As String
Dim Zone As Integer
Dim NomFeuille As String
NoColonne = ActiveCell.Column
NoCI = ThisWorkbook.Sheets("Heures").Range("A1")
DernLigne = Worksheets("Heures").Range("C" & Rows.Count).End(xlUp).Row
Initiale = Worksheets("Heures").Cells(2, NoColonne) 'Ligne 2 et Colonne...
For j = 2 To 50
If Initiale = ThisWorkbook.Sheets("Données").Range("D" & j) Then 'Recherche nom auteur par rapport aux initiales
Intervenant = ThisWorkbook.Sheets("Données").Range("C" & j)
Exit For
End If
Next j
MsgBox "Récupérations des heures de: " & Intervenant
Intervenant = Mid(Intervenant, InStr(Intervenant, " ") + 1) 'On ne garde que le nom de famille
Sheets("Heures").Range(Cells(4, NoColonne), Cells(162, NoColonne)).ClearContents 'Effacer la colonne selectionné des lignes 4 à 162
'Pour chaque semaines
For Ligne = 4 To DernLigne
'Gestion des années
Année = ThisWorkbook.Sheets("Heures").Range("A4")
If Ligne > 57 Then
Année = Année + 1
End If
If Ligne > 110 Then
Année = Année + 1
End If
'On Error GoTo ErrorHandler
CheminFichierXL = "R:\COMMUN\01-ORIGINAUX LBM\Bureau\POINTAGE\"
FichierXL = Intervenant & "_Pointage "
If Dir(CheminFichierXL & Année, vbDirectory) <> vbNullString Then 'Pour tester si dossier existe
' Exit Sub
'ErrorHandler:
' MsgBox "Il n'y a pas de fichier ", vbInformation, "Pas de fichier"
'Cancel = True
'Application.EnableEvents = True 'Résactiver les évènements pendant la macro
FichierAouvrir = FichierXL & Année & ".xls"
With appxl
.Workbooks.Open CheminFichierXL & Année & "\" & FichierAouvrir
' .Visible = False
.Visible = True
End With
NoSem = Right(ThisWorkbook.Sheets("Heures").Range("C" & Ligne), 2)
If NoSem = "01" Then
NomFeuille = "01-04"
Zone = 1
End If
If NoSem = "02" Then
NomFeuille = "01-04"
Zone = 2
End If
If NoSem = "03" Then
NomFeuille = "01-04"
Zone = 3
End If
If NoSem = "04" Then
NomFeuille = "01-04"
Zone = 4
End If
If NoSem = "05" Then
NomFeuille = "05-08"
Zone = 1
End If
If NoSem = "06" Then
NomFeuille = "05-08"
Zone = 2
End If
If NoSem = "07" Then
NomFeuille = "05-08"
Zone = 3
End If
If NoSem = "08" Then
NomFeuille = "05-08"
Zone = 4
End If
If NoSem = "09" Then
NomFeuille = "09-12"
Zone = 1
End If
If NoSem = "10" Then
NomFeuille = "09-12"
Zone = 2
End If
If NoSem = "11" Then
NomFeuille = "09-12"
Zone = 3
End If
If NoSem = "12" Then
NomFeuille = "09-12"
Zone = 4
End If
If NoSem = "13" Then
NomFeuille = "13-16"
Zone = 1
End If
If NoSem = "14" Then
NomFeuille = "13-16"
Zone = 2
End If
If NoSem = "15" Then
NomFeuille = "13-16"
Zone = 3
End If
If NoSem = "16" Then
NomFeuille = "13-16"
Zone = 4
End If
If NoSem = "17" Then
NomFeuille = "17-20"
Zone = 1
End If
If NoSem = "18" Then
NomFeuille = "17-20"
Zone = 2
End If
If NoSem = "19" Then
NomFeuille = "17-20"
Zone = 3
End If
If NoSem = "20" Then
NomFeuille = "17-20"
Zone = 4
End If
If NoSem = "21" Then
NomFeuille = "21-24"
Zone = 1
End If
If NoSem = "22" Then
NomFeuille = "21-24"
Zone = 2
End If
If NoSem = "23" Then
NomFeuille = "21-24"
Zone = 3
End If
If NoSem = "24" Then
NomFeuille = "21-24"
Zone = 4
End If
If NoSem = "25" Then
NomFeuille = "25-28"
Zone = 1
End If
If NoSem = "26" Then
NomFeuille = "25-28"
Zone = 2
End If
If NoSem = "27" Then
NomFeuille = "25-28"
Zone = 3
End If
If NoSem = "28" Then
NomFeuille = "25-28"
Zone = 4
End If
If NoSem = "29" Then
NomFeuille = "29-32"
Zone = 1
End If
If NoSem = "30" Then
NomFeuille = "29-32"
Zone = 2
End If
If NoSem = "31" Then
NomFeuille = "29-32"
Zone = 3
End If
If NoSem = "32" Then
NomFeuille = "29-32"
Zone = 4
End If
If NoSem = "33" Then
NomFeuille = "33-36"
Zone = 1
End If
If NoSem = "34" Then
NomFeuille = "33-36"
Zone = 2
End If
If NoSem = "35" Then
NomFeuille = "33-36"
Zone = 3
End If
If NoSem = "36" Then
NomFeuille = "33-36"
Zone = 4
End If
If NoSem = "37" Then
NomFeuille = "37-40"
Zone = 1
End If
If NoSem = "38" Then
NomFeuille = "37-40"
Zone = 2
End If
If NoSem = "39" Then
NomFeuille = "37-40"
Zone = 3
End If
If NoSem = "40" Then
NomFeuille = "37-40"
Zone = 4
End If
If NoSem = "41" Then
NomFeuille = "41-44"
Zone = 1
End If
If NoSem = "42" Then
NomFeuille = "41-44"
Zone = 2
End If
If NoSem = "43" Then
NomFeuille = "41-44"
Zone = 3
End If
If NoSem = "44" Then
NomFeuille = "41-44"
Zone = 4
End If
If NoSem = "45" Then
NomFeuille = "45-48"
Zone = 1
End If
If NoSem = "46" Then
NomFeuille = "45-48"
Zone = 2
End If
If NoSem = "47" Then
NomFeuille = "45-48"
Zone = 3
End If
If NoSem = "48" Then
NomFeuille = "45-48"
Zone = 4
End If
If NoSem = "49" Then
NomFeuille = "49-52"
Zone = 1
End If
If NoSem = "50" Then
NomFeuille = "49-52"
Zone = 2
End If
If NoSem = "51" Then
NomFeuille = "49-52"
Zone = 3
End If
If NoSem = "52" Then
NomFeuille = "49-52"
Zone = 4
End If
Set Fichier = appxl.Windows(FichierAouvrir)
Fichier.Activate
Set feuille = appxl.Sheets(NomFeuille)
'---------------------------------Zone 1 ---------------
If Zone = 1 Then
For i = 7 To 17
If feuille.Range("C" & i) = NoCI Then
'Range(Colonne & Ligne) = feuille.Range("P" & i) 'NoColonne
Cells(Ligne, NoColonne) = feuille.Range("P" & i)
End If
Next
End If
'---------------------------------Zone 2 ---------------
If Zone = 2 Then
For i = 7 To 17
If feuille.Range("S" & i) = NoCI Then
Cells(Ligne, NoColonne) = feuille.Range("AF" & i)
End If
Next
End If
'---------------------------------Zone 3 ---------------
If Zone = 3 Then
For i = 26 To 36
If feuille.Range("C" & i) = NoCI Then
Cells(Ligne, NoColonne) = feuille.Range("P" & i)
End If
Next
End If
'---------------------------------Zone 4 ---------------
If Zone = 4 Then
For i = 26 To 36
If feuille.Range("S" & i) = NoCI Then
Cells(Ligne, NoColonne) = feuille.Range("AF" & i)
End If
Next
End If
End If
Next 'Ligne
'-------------------Fermer le pointage
Année = ThisWorkbook.Sheets("Heures").Range("A4")
With appxl
If Dir(CheminFichierXL & Année, vbDirectory) <> vbNullString Then 'Pour tester si dossier existe
.Workbooks(FichierXL & Année & ".xls").Close SaveChanges:=False
End If
If Dir(CheminFichierXL & Année + 1, vbDirectory) <> vbNullString Then 'Pour tester si dossier existe
.Workbooks(FichierXL & Année + 1 & ".xls").Close SaveChanges:=False
End If
If Dir(CheminFichierXL & Année + 2, vbDirectory) <> vbNullString Then 'Pour tester si dossier existe
.Workbooks(FichierXL & Année + 2 & ".xls").Close SaveChanges:=False
End If
End With
End Sub |
Partager