IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

MFC à 5 conditions [XL-2003]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Février 2009
    Messages
    188
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 188
    Par défaut MFC à 5 conditions
    bonsoir,

    sur un tableau type calendrier zone D1:AI61 j'aimerais traiter par différentes couleur des périodes définies

    en jaune le samedi
    en vert le dimanche
    en gris les jours fériés
    en bleu l'été
    en marron les pvs (petites vacances scolaires)

    j'ai codé un vba plutôt brut et basique essayant de traiter mes problèmes mais je me retrouve forcemment bloqué ne sachant pas relier par code une date donnée à une plade de dates correspondant à une période

    pourriez-vous m'aider svp ?


    exemple concret :

    -les jours fériés qui sont dans mon onglet en zone J64:J74
    commen faire en sorte que les jours fériés correspondant se retrouve coloré dans ma zone calendrier ?

    -même problèmatique mais pour l'été et les pvs en zone N64:L68 qui sont eux par contre délimités par des dates de début et de fin de validité ?


    merci par avance

    bonne soirée
    Fichiers attachés Fichiers attachés

  2. #2
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132

  3. #3
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Essaies ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Private Sub CommandButton1_Click()
    Dim DerLigne As Long, j As Long
    Dim DerCol As Integer, i As Integer
    Dim Flag As Boolean
     
    Application.ScreenUpdating = False
    With Sheets("Calendrier_base")
        DerLigne = .Cells(.Rows.Count, "D").End(xlUp).Row
        DerCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
        .Range(.Cells(2, 5), .Cells(DerLigne, DerCol)).Interior.ColorIndex = xlNone
        j = 2
        Do
            For i = 5 To DerCol
                If .Cells(j, i).Value <> "" Then
                    If Not Flag Then
                        Select Case Weekday(.Cells(j, i).Value, vbMonday)
                            Case 6: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 27
                            Case 7: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 35
                        End Select
                        Set c = .Range("J64:J74").Find(CDate(.Cells(j, i).Value), LookIn:=xlValues, lookat:=xlWhole)
                        If Not c Is Nothing Then
                            Set c = Nothing
                            .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 15
                        End If
                    Else
                        Select Case .Cells(j, i)
                            Case "G": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 45
                            Case "D": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 42
                        End Select
                    End If
                End If
            Next i
            j = j + 2
            If Flag Then j = j + 1
            Flag = Not Flag
        Loop Until j >= DerLigne
    End With
    End Sub

  4. #4
    Membre confirmé
    Inscrit en
    Février 2009
    Messages
    188
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 188
    Par défaut
    merci mercatog ça fonctionne parfaitement

    je vais prendre le temps de comprendre le code maintenant

    finalement je me retrouve devant un problème si pour chaque mois j'insère une ligne supplémentaire après les 2 lignes concernées par la colorisation.

    je pensais que cela se passait en bout de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     j = j + 2
            If Flag Then j = j + 1
            Flag = Not Flag
    mais même en incrémentant j cela bloque


    là j'ai laissé tel quel mais aimerais savoir comment faire ?

    merci par avance

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Private Sub CommandButton1_Click()
    Dim DerLigne As Long, j As Long
    Dim DerCol As Integer, i As Integer
    Dim Flag As Boolean
     
    With Sheets("Calendrier_base")
        DerLigne = .Cells(.Rows.Count, "D").End(xlUp).Row
        DerCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        .Range(.Cells(2, 3), .Cells(DerLigne, DerCol)).Interior.ColorIndex = xlNone
        j = 2
        Do
            For i = 3 To DerCol
                If .Cells(j, i).Value <> "" Then
                Debug.Print .Cells(j, i)
                Debug.Print Weekday(.Cells(j, i), vbMonday)
                    If Not Flag Then
                        Select Case Weekday(.Cells(j, i).Value, vbMonday)
                            Case 6: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 27
                            Case 7: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 35
                        End Select
                        Set c = .Range("H78:H88").Find(CDate(.Cells(j, i).Value), LookIn:=xlValues, lookat:=xlWhole)
                        If Not c Is Nothing Then
                            Set c = Nothing
                            .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 15
                        End If
                    Else
                        Select Case .Cells(j, i)
                            Case "G": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 45
                            Case "U": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 45
                            Case "D": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 42
                        End Select
                    End If
                End If
            Next i
            j = j + 2
            If Flag Then j = j + 1
            Flag = Not Flag
        Loop Until j >= DerLigne
        Cells(1, 1).Select
    End With
     
    End Sub
    Fichiers attachés Fichiers attachés

  5. #5
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Private Sub CommandButton1_Click()
    Dim DerLigne As Long, j As Long
    Dim DerCol As Integer, i As Integer
    Dim Flag As Boolean
     
    With Sheets("Calendrier_base")
        DerLigne = .Cells(.Rows.Count, "D").End(xlUp).Row
        DerCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        .Range(.Cells(2, 3), .Cells(DerLigne, DerCol)).Interior.ColorIndex = xlNone
        j = 2
        Do
            For i = 3 To DerCol
                If .Cells(j, i).Value <> "" Then
                    If Not Flag Then
                        Select Case Weekday(.Cells(j, i).Value, vbMonday)
                            Case 6: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 27
                            Case 7: .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 35
                        End Select
                        Set c = .Range("H78:H88").Find(CDate(.Cells(j, i).Value), LookIn:=xlValues, lookat:=xlWhole)
                        If Not c Is Nothing Then
                            Set c = Nothing
                            .Range(.Cells(j, i), .Cells(j + 1, i)).Interior.ColorIndex = 15
                        End If
                    Else
                        Select Case .Cells(j, i)
                            Case "G", "U": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 45
                            Case "D": .Range(.Cells(j - 1, i), .Cells(j - 2, i)).Interior.ColorIndex = 42
                        End Select
                    End If
                End If
            Next i
    'ICI on va se déplacer de 2 lignes en bas si on est en première ligne du mois, sinon de 4 lignes pour se retrouver en première ligne du mois suivant
            j = j + 2                   'On passe à 2lignes plus bas du tableau
            If Flag Then j = j + 2      'si Flag=True signifie on doit ajouter encore 2lignes pour passer à la première ligne du mois suivant
            Flag = Not Flag
        Loop Until j >= DerLigne
    End With
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2013] Planning avec condition et MFC
    Par soufege dans le forum Excel
    Réponses: 0
    Dernier message: 09/03/2014, 14h46
  2. [XL-2013] MFC avec 4 conditions
    Par bolide7 dans le forum Excel
    Réponses: 2
    Dernier message: 23/02/2014, 18h10
  3. [XL-2003] MFC avec la condition OU
    Par bolide7 dans le forum Excel
    Réponses: 4
    Dernier message: 12/09/2013, 00h09
  4. MFC - Top 5 + autre condition
    Par stanley1415 dans le forum Excel
    Réponses: 2
    Dernier message: 10/05/2013, 17h58
  5. 4ème condition dans une MFC
    Par Smint dans le forum IHM
    Réponses: 11
    Dernier message: 11/10/2007, 21h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo