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
|
Sub ColoriageResa()
Dim IndLigneResa As Integer
Dim IndLigneAppart As Integer
Dim IndJourDébut As Integer
Dim Sortie As Boolean
IndLigneResa = 3
Sortie = False
'Tant qu'il reste des lignes de resa à traiter
While ThisWorkbook.Worksheets(1).Range("A" & IndLigneResa).Value <> "" And Not Sortie
'On se place sur le 1er jour du planning
IndJourDébut = 2
'On cherche la colonne correspondant au jour de début de la résa
While ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut).Value <> ThisWorkbook.Worksheets(1).Range("B" & IndLigneResa).Value And ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut).Value <> ""
IndJourDébut = IndJourDébut + 1
Wend
'si on a pas trouvé le jour de la résa, y'a un problème, on sort
If ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut).Value = "" Then
MsgBox ("Erreur Date résa" & " B" & IndLigneResa)
Sortie = True
'si on a trouvé, il faut colorier et mettre le nom dans les bonnes cases
Else
'On recherche d'abord la ligne à colorier correspondant à l'appart de la resa
IndLigneAppart = 2
While ThisWorkbook.Worksheets(2).Cells(IndLigneAppart, 1).Value <> ThisWorkbook.Worksheets(1).Range("A" & IndLigneResa).Value And ThisWorkbook.Worksheets(2).Cells(IndLigneAppart, 1).Value <> ""
IndLigneAppart = IndLigneAppart + 1
Wend
' si on ne l'a pas trouvée: erreur
If ThisWorkbook.Worksheets(2).Cells(IndLigneAppart, 1).Value = "" Then
MsgBox ("Erreur Appart résa" & " A" & IndLigneResa)
Sortie = True
End If
If Not Sortie Then
'on inscrit le nom du mec qui a reservé
ThisWorkbook.Worksheets(2).Cells(IndLigneAppart, IndJourDébut).Value = ThisWorkbook.Worksheets(1).Range("D" & IndLigneResa).Value
'on cherche ensuite la date de fin de séjour tout en coloriant à chaque fois la case
While ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut).Value <= ThisWorkbook.Worksheets(1).Range("C" & IndLigneResa).Value And ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut).Value <> ""
ThisWorkbook.Worksheets(2).Cells(IndLigneAppart, IndJourDébut).Interior.Color = RGB(0, 0, 255)
IndJourDébut = IndJourDébut + 1
Wend
'si on est à la fin mais qu'on est pas sorti du planning, c'est qu'on a pas trouvé la date de fin => erreur.
If ThisWorkbook.Worksheets(2).Cells(1, IndJourDébut - 1).Value <> ThisWorkbook.Worksheets(1).Range("C" & IndLigneResa).Value Then
MsgBox ("Erreur Date résa" & " C" & IndLigneResa)
Sortie = True
End If
End If
End If
'on passe à la resa suivante
IndLigneResa = IndLigneResa + 1
Wend
End Sub |
Partager