Option Explicit

' ======================================================================
' =                                       DESSINE L'ENTETE DES PARTIES                                               =
' ======================================================================
' Dessine l'entete des parties.
' Ecrit "Partie N° (Incréménté a chaque tirage de nouvelles partie).
' Défini les couleurs et les bordures.
' ---------------------------------------------------------------------------------------------------------------------------

Sub Entete()
Dim LesP As Integer  ' sert a composer les 2e partie

Application.ScreenUpdating = False
With Sheets("Concours")
    If .Range("J1") = "En cours" Then
        LesP = Range("H1") + 4
    Else
        LesP = 1
    End If

    ' ----------------------
    ' Plage d'entete
    ' ----------------------
    With .Range("A" & LesP & ":G" & LesP)
        .RowHeight = 33
        .Interior.Color = RGB(150, 240, 150)            ' Vert
        '.Interior.Color = RGB(250, 200, 150)           ' Orange (deuxieme couleur pour la consolante)
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlMedium
        .Borders(xlInsideVertical).LineStyle = xlNone
    End With

    ' ----------------------------------
    ' Cellule du titre d'entete
    ' ----------------------------------
    With Range("D" & LesP)
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Font.Bold = True
        .Font.Name = "Calibri"
        .Font.Size = 18
        .Value = "Concours Partie N° " & Partie
    End With

    ' -----------------------------------------
    ' Plages des "N°" de joueurs
    ' -----------------------------------------
    With .Range("A" & LesP + 1 & ":G" & LesP + 1)
        .RowHeight = 18
        .Interior.Color = RGB(230, 250, 230)
        '.Interior.Color = RGB(150, 240, 150)
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlMedium
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Font.Name = "Calibri"
        .Font.Size = 12
        .Font.Bold = True
        '.Value = "N°"
    End With
    .Range("A" & LesP + 1 & ",E" & LesP + 1) = "N°"
    .Range("B" & LesP + 1 & ",F" & LesP + 1) = "Equipes"
    .Range("C" & LesP + 1 & ",G" & LesP + 1) = "G/P"
    .Range("D" & LesP + 1) = "Terrain"
 
End With
Application.ScreenUpdating = False

End Sub


' ======================================================================
' =                           DESSINE LA GRILLE POUR LES "Tete a tete "                                        =
' ======================================================================
'  Fixe la hauteur de la ligne 1 (Ligne de d'entete
'  Fixe la largeur pour chaque colonne
'  Défini le centrage horizontal et vertical
' ---------------------------------------------------------------------------------------------------------------------------
Sub Grille1()

Dim X As Integer
Dim Y As Byte

Application.ScreenUpdating = False

With Worksheets("Concours")
    'Pl = 4 - 2
    'Y = 2

    For X = 4 To .Range("Dl_1") Step Tournois
            
        With .Range("A" & X & ":G" & X)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .Font.Bold = True
            .Font.Name = "Calibri"
            .Font.Size = 12
            .Borders.LineStyle = xlContinuous
            .Borders.Weight = xlMedium
        End With
        
        .Range("B" & X & ",F" & X).ColumnWidth = 28
        .Range("D" & X) = "N°"
        
        X = X + 1
        
    Next X
    
End With
Application.ScreenUpdating = True

End Sub


'' ======================================================================
'' =                           DESSINE LES ENTETES POUR LES PARTIES                                     =
'' ======================================================================
'' Dessine l'entete des parties.
'' Ecrit "Partie N° (Incréménté a chaque tirage de nouvelles partie).
'' Défini les couleurs et les bordures.
'' ---------------------------------------------------------------------------------------------------------------------------
'                ' POINT D'ARRET SUR LIGNE EN DESSOUS
Public Sub EnteteLesP()
  ' premiere ligne d'une partie
Application.ScreenUpdating = False
        With Worksheets("Concours")
        
            .Unprotect
            .Range("Dl_" & Partie) = .Cells(Rows.Count, "A").End(xlUp).Row

            If .Range("J1") = "En cours" Then

                Pl = .Range("Pl_" & Partie) - 2
            Else
                Pl = 1

            End If

            ' --------------
            ' Plage d'entete
            ' --------------

            With .Range("A" & Pl - 1 & ":G" & Pl - 1 & ",i" & Pl - 1 & ":O" & Pl - 1)

                .RowHeight = 33
                .Interior.Color = RGB(150, 240, 150)                                    ' Vert
                '        .Interior.Color = RGB(250, 200, 150)                           ' Orange (deuxieme couleur pour la consolante)
                .Borders.LineStyle = xlContinuous
                .Borders.Weight = xlMedium
                .Borders(xlInsideVertical).LineStyle = xlNone

            End With

            ' -------------------------
            ' Cellule du titre d'entete
            ' -------------------------

            With .Range("D" & Pl - 1 & ",L" & Pl - 1)

                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .Font.Bold = True
                .Font.Name = "Calibri"
                .Font.Size = 18
                .Value = "Concours Partie N° " & Partie

            End With

            ' ----------------------------------------------
            ' Ligne d'espacement entre l'entete et la grille
            ' ----------------------------------------------

            With .Range("A" & Pl & ":G" & Pl & ",i" & Pl & ":O" & Pl)

                .RowHeight = 18
                .Interior.Color = RGB(230, 250, 230)
                .Borders.LineStyle = xlContinuous
                .Borders.Weight = xlMedium
                .HorizontalAlignment = xlCenter
                .Font.Name = "Calibri"
                .Font.Size = 12
                .Font.Bold = True

            End With
            
            ' --------------------------
            ' Plages des noms de joueurs
            ' --------------------------
            .Range("A" & Pl & ",E" & Pl & ",i" & Pl & ",M" & Pl) = "N°"
            .Range("B" & Pl & ",F" & Pl & ",J" & Pl & ",N" & Pl) = "Equipes"
            .Range("C" & Pl & ",G" & Pl & ",K" & Pl & ",O" & Pl) = "G/P"  'Gagné/Perdu
            .Range("D" & Pl & ",L" & Pl) = "Terrain"

            .Range("A" & Pl + 1).RowHeight = 11 ' epaisseur de la ligne d'espacement

        End With

Application.ScreenUpdating = False

End Sub


'' ======================================================================
'' =                                DESSINE LA GRILLE POUR LES "Doublettes"                                      =
'' ======================================================================

Sub Grille1Doublette()

Dim X As Integer
Dim Y As Byte

Application.ScreenUpdating = False
Dl = Cells(Rows.Count, "A").End(xlUp).Row

Tournois = 2

With Worksheets("Concours")
    'Pl = 4 - 2
    'Y = 2
'    For X = Pl + Y To .Range("Dl_1") Step Tournois
For X = 4 To Dl Step Tournois
    'For X = Pl + Y To Dl Step Tournois
    
        .Range("A" & X & ":A" & X + 1).Merge
        .Range("C" & X & ":C" & X + 1).Merge
        .Range("D" & X & ":D" & X + 1).Merge
        .Range("E" & X & ":E" & X + 1).Merge
        .Range("G" & X & ":G" & X + 1).Merge
         
        With .Range("A" & X & ":G" & X + 1)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .Font.Bold = True
            .Font.Name = "Calibri"
            .Font.Size = 12
            .Borders.LineStyle = xlContinuous
            .Borders.Weight = xlMedium
        End With
        
        .Range("D" & X) = "N°"
        
        X = X + 1
        
    Next X
    .Range("B" & X & ",F" & X).ColumnWidth = 28
    
End With

Application.ScreenUpdating = True

End Sub

'' ======================================================================
'' =                                DESSINE LA GRILLE POUR LES "Triplettes"                                      =
'' ======================================================================
'' Défini la largeur des colonnes.
'' Ecrit "Contre" dans la cellule "D" de la grille
'' ---------------------------------------------------------------------------------------------------------------------------
'
Sub Grille1Triplette()

    Dim X As Integer
    'Dim Z As Integer

    Application.ScreenUpdating = False

    Dl = Worksheets("Inscriptions").Cells(Rows.Count, "N").End(xlUp).Row

    Dl = (Dl * 2)

    'Z = Tournois + 1

    'Pl = 4 '3

    With Worksheets("Concours")

        For X = 4 To Dl Step Tournois + 1
        
            .Range("A" & X & ":A" & X + 2).Merge
            .Range("C" & X & ":C" & X + 2).Merge
            .Range("D" & X & ":D" & X + 2).Merge
            .Range("E" & X & ":E" & X + 2).Merge
            .Range("G" & X & ":G" & X + 2).Merge
            
            With .Range("A" & X & ":G" & X + 2)
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .Font.Bold = True
                .Font.Name = "Calibri"
                .Font.Size = 12
                .Borders.LineStyle = xlContinuous
                .Borders.Weight = xlMedium
                .Offset(1, 0).RowHeight = 18
            End With
            
            .Range("B" & X & ",F" & X).ColumnWidth = 28
            .Range("C" & X & ",G" & X).ColumnWidth = 3.75
            .Range("D" & X & ":D" & X + 1).Value = "N°"

        Next X

    End With

Application.ScreenUpdating = True

End Sub

' ======================================================================
' =                          DESSINE LES GRILLES POUR LE   "Tete a tete"                                     =
' ======================================================================
'  Fixe la hauteur de la ligne 1 (Ligne de d'entete
'  Fixe la largeur pour chaque colonne
'  Défini le centrage horizontal et vertical
' ---------------------------------------------------------------------------------------------------------------------------
Sub GrilleLesP()

Dim X As Integer
Dim Y As Byte
Dim Z As Integer
Dim Dl2 As Integer
Dim i As Byte

Application.ScreenUpdating = False

With Worksheets("Concours")

    Compte = Worksheets("Inscriptions").Cells(Rows.Count, "N").End(xlUp).Row - 1

    If .OptionButton1.Value = True Then

        Compte = Compte
        Tournois = 1

    End If

    If .OptionButton2.Value = True Then

        Compte = Compte + (Compte / 3 * 2)
        Tournois = 2

    End If

    If .OptionButton3.Value = True Then

        Compte = Compte * 3
        Tournois = 3

    End If

    If Tournois = 0 Then

        MsgBox " Il faut faire un choix de type de tournois, voir : U2, V2 ou W2 !"
        End

    End If
        '##########################################

        ''''''Dl2 = Worksheets("Inscriptions").Cells(Rows.Count, "N").End(xlUp).Row - 1     ' Trouver la derniere ligne de la colonne B
        ''''''Dl2 = Dl2 + Application.WorksheetFunction.RoundUp(Dl2 / 2, 0)
    Z = Tournois + 1

    Pl = Range("Pl_" & Partie)     '  ligne 4 -1 car, y ajoute 1
    Dl = .Cells(Rows.Count, "A").End(xlUp).Row

    For X = Pl To Dl Step Z
        
            Select Case Tournois
                Case Is = 1: i = 0
                Case Is = 2: i = 1
                Case Is = 3: i = 2
            End Select

            With .Range("A" & X & ":G" & X + i & ",I" & X & ":O" & X + i)
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
                .Font.Bold = True
                .Font.Name = "Calibri"
                .Font.Size = 12
                .Borders.LineStyle = xlContinuous
                .Borders.Weight = xlMedium
            
            End With
            
            With .Range("A" & X & ":A" & X + i & ",E" & X & ":E" & X + i & ",i" & X & ":i" & X + i & ",M" & X & ":M" & X + i)
                If i >= 0 Then .Merge
                .ColumnWidth = 4.75
                .Offset(1, 0).RowHeight = 18
            End With
            
            With .Range("C" & X & ":C" & X + i & ",G" & X & ":G" & X + i & ",K" & X & ":K" & X + i & ",O" & X & ":O" & X + i)
                If i > 0 Then .Merge
                .ColumnWidth = 3.75
            End With
            
            With .Range("D" & X & ":D" & X + i & ",L" & X & ":L" & X + i)
                If i > 0 Then .Merge
                .Value = "N°"
            End With
            
            .Range("B" & X & ",F" & X & ",J" & X & ",N" & X).ColumnWidth = 28
            
        Next X

End With

Application.ScreenUpdating = True

End Sub