Affichage format date

StrikeBEH

XLDnaute Occasionnel
Bonjour,
J'utilise la boucle:
Code:
Dim i As Integer
Dim j As String
For i = 1 To Day(WorksheetFunction.EoMonth(Date, 0))
If i < 10 Then
    j = "0" & i
    Else
    j = i
End If
Range("B" & i + 6) = j & UCase(Left(Format(i, "ddd"), 1))
Next i

pour afficher dans la colonne "B" les jours que comprend le mois en cours (février en l'occurence) sous la forme "01D", "02L"...

La lettre derrière le chiffre désigne le jour de la semaine.

Y aurait-il un code plus "simple" pour arriver à ce même résultat ?

Par avance merci à tous,
 

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Re

Bon alors en plus du "pâquet de Modeste", j'ai pris un peu d'essence de myDearFriend (AKA Mdf AKA Didier F.)
j'ai tout mis dans le caquelon, et cela donne cet imparfaite mixture.
Si le cœur vous en dit, amender la chose.
Moi je vais faire mes fumigations.
Code:
Sub UnperfectSubButjustAPerfectDay()
Dim Form$, IntV&, PAQ As Date, An As Integer, DF(1 To 13) As Variant, D As Date, L As Byte
An = Year(Date)
PAQ = Evaluate("=DATE(" & An & ",3,29.56+0.979*MOD(204-11*MOD(" & An & ",19),30)- WEEKDAY(DATE(" & An & ",3,28.56+0.979*MOD(204-11*MOD(" & An & ",19),30))))")
D = PAQ
For L = 1 To 13
DF(L) = Choose(L, DateSerial(An, 1, 1), CDate(D), CDate(D + 1), DateSerial(An, 5, 1), DateSerial(An, 5, 8), CDate(D + 39), CDate(D + 49), CDate(D + 50), DateSerial(An, 7, 14), DateSerial(An, 8, 15), DateSerial(An, 11, 1), DateSerial(An, 11, 11), DateSerial(An, 12, 25))
Next L
[JF1:JR1] = DF: [JF1:JR1].Name = "lJF"
IntV = CLng(Day(DateSerial(An, Month(Date) + 1, 0)))
Form = "DATE(YEAR(TODAY()),MONTH(TODAY()),ROW()-6)"
    With Range("B7")
        .Resize(IntV, 2).Clear
        With .Resize(IntV, 1)
            .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
            .Value = .Value
        With .Offset(, 1)
            .FormulaR1C1 = "=INDEX({""CC"";""JT"";""JT"";""JT"";""JT"";""JT"";""CR""},WEEKDAY(" & Form & "))"
            .Value = .Value
        End With
        With .Resize(IntV, 2)
            .FormatConditions.Add Type:=2, Formula1:="=OU(GAUCHE($C7)=""C"";NON(ESTNA(EQUIV(DATE(ANNEE(AUJOURDHUI());MOIS(AUJOURDHUI());LIGNE()-6);lJF;0))))"
            .FormatConditions(1).Interior.ThemeColor = 3
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
        End With
    End With
End With
End Sub
 

Modeste geedee

XLDnaute Barbatruc
Re : Affichage format date

Bonsour® :cool:

je suis cependant intrigué par ceci :
With .Resize(IntV, 2)
.FormatConditions.Add Type:=2, Formula1:="=OU(GAUCHE($C7)=""C"";NON(ESTNA(EQUIV(DATE(ANNEE(AUJOURDHUI());MOIS(AUJOURDHUI());LIGNE()-6);lJF;0))))"
.FormatConditions(1).Interior.ThemeColor = 3
.FormatConditions(.FormatConditions.Count).SetFirstPriority
End With

car après exécution et de façon erratique je trouve cela :
Capture.jpg
Ce lien n'existe plus

????
 

Pièces jointes

  • Capture.jpg
    Capture.jpg
    55.9 KB · Affichages: 49
  • Capture.jpg
    Capture.jpg
    55.9 KB · Affichages: 55
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Re,

Modeste Geedee
J'ai testé en changeant la date du PC (je m'étais mis en mai 2014)
et de mémoire la MFC se faisait bien (jour férié inclus)
L'imparfait, c'était pour la valeur JT qui reste affecté au jour qui sont fériés (pour le moment)

EDITION:
J'ai beau regarder ta copie d'écran, je ne vois pas ce qui te chagrine sur celle-ci.
Le 1/2/14 est bien un samedi.

Résultat pour mai 2014
mfctestok.jpg
 
Dernière édition:

Modeste geedee

XLDnaute Barbatruc
Re : Affichage format date

Bonsour®
Re,J'ai beau regarder ta copie d'écran, je ne vois pas ce qui te chagrine sur celle-ci.-

ce n'est pas grave ...
tu remarquera sur ma copie d'écran que la condition de la MEFC fait référence de façon erratique à $C1048574 en lieu et place de $C7 ???
je n'arrive pas identifier dans quelles conditions cela se produit...
et pourtant cela se reproduit aléatoirement ?
 

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

@Staple,

J'ai adapté ton code ainsi pour la création de mon tableau...
Code:
Sub Test()
    Range("B1:K4,B5:K5").MergeCells = True
    With Range("B1:K4,B5:K5,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6")
        .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
        .Interior.Color = 39423
        .Font.Size = 9
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
    End With
    Range("B5") = UCase(Format(Date, "mmmm yyyy"))
    Range("B6") = "Date"
    Range("C6") = "Type"
    Range("D6") = "Heure Début" & Chr(10) & "de Service"
    Range("E6") = "Heure Fin" & Chr(10) & "de Service"
    Range("F6") = "Nb Heures" & Chr(10) & "Travaillées"
    Range("G6") = "Heures" & Chr(10) & "de jour"
    Range("H6") = "Heures" & Chr(10) & "de nuit"
    Range("I6") = "Heures" & Chr(10) & "à 150%"
    Range("J6") = "Heures" & Chr(10) & "à 200%"
    Range("K6") = "Heures" & Chr(10) & "Sam/Dim"
    
Dim Form$, IntV&
IntV = CLng(Day(DateSerial(Year(Date), Month(Date) + 1, 0)))
Form = "DATE(YEAR(TODAY()),MONTH(TODAY()),ROW()-6)"
    With Range("B7")
        .Resize(IntV, 2).Clear
        With .Resize(IntV, 1)
'            .Font.Size = 10
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
            .Value = .Value
        With .Offset(, 1)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .FormulaR1C1 = "=INDEX({""CC"";""JT"";""JT"";""JT"";""JT"";""JT"";""CR""},WEEKDAY(" & Form & "))"
            .Value = .Value
        End With
        With .Resize(IntV, 2)
            .FormatConditions.Add Type:=2, Formula1:="=GAUCHE($C7)=""C"""
            .FormatConditions(1).Interior.ThemeColor = 3
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
        End With
        
        With .Resize(IntV, 10)
             .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
        End With
        
        With .Resize(IntV + 1, 10)
            .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
            .Borders(xlInsideVertical).LineStyle = xlContinuous
        End With
        
    End With
End With

et j'aimerai fusionner les cellules B35 et C35 et d'y écrire "TOTAUX"...
J'ai essayé avec .Resize(InvT+1,2) mais cela ne fonctionne pas !
 

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Re

StrikeBEH
Il m'est interdit de m'approcher d'un classeur ou d'un code VBA qui fait mention de cellules fusionnées.
Si je déroge à cette règle, (ma santé physique déjà dégradée par une grippe, et donc ma capacité de discernement amoindrie par ce fait), ma santé mentale risque une altération des plus sévère.
(Déjà qu'en temps normal, je suis sur que certains d'entre vous pensent que mon carafon est déjà bien dézingué ;) )

C'est pourquoi je refuse de fusionner quoique ce soit avec qui que soit.

Par contre si tu dé-fusionnes tes cellules, alors je reste dans le fil et je poursuis l'aventure, comme dirait le grand escogriffe de TF1...
 

Modeste geedee

XLDnaute Barbatruc
Re : Affichage format date

Bonsour®

VB:
Sub Test()
     Range("B1:K4,B5:K5").MergeCells = True
     With Range("B1:K4,B5:K5,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6")
         .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
         .Interior.Color = 39423
         .Font.Size = 9
         .Font.Bold = True
         .HorizontalAlignment = xlCenter
         .VerticalAlignment = xlCenter
     End With
     Range("B5") = UCase(Format(Date, "mmmm yyyy"))
     Range("B6") = "Date"
     Range("C6") = "Type"
     Range("D6") = "Heure Début" & Chr(10) & "de Service"
     Range("E6") = "Heure Fin" & Chr(10) & "de Service"
     Range("F6") = "Nb Heures" & Chr(10) & "Travaillées"
     Range("G6") = "Heures" & Chr(10) & "de jour"
     Range("H6") = "Heures" & Chr(10) & "de nuit"
     Range("I6") = "Heures" & Chr(10) & "à 150%"
     Range("J6") = "Heures" & Chr(10) & "à 200%"
     Range("K6") = "Heures" & Chr(10) & "Sam/Dim"
     
 Dim Form$, IntV&
 IntV = CLng(Day(DateSerial(Year(Date), Month(Date) + 1, 0)))
 Form = "DATE(YEAR(TODAY()),MONTH(TODAY()),ROW()-6)"
     With Range("B7")
     '-----------------------------------------------------
         .Resize(33, 10).Clear
     '-----------------------------------------------------
         With .Resize(IntV, 1)
 '            .Font.Size = 10
             .HorizontalAlignment = xlCenter
             .VerticalAlignment = xlCenter
             .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
             .Value = .Value
         With .Offset(, 1)
             .HorizontalAlignment = xlCenter
             .VerticalAlignment = xlCenter
             .FormulaR1C1 = "=INDEX({""CC"";""JT"";""JT"";""JT"";""JT"";""JT"";""CR""},WEEKDAY(" & Form & "))"
             .Value = .Value
         End With
         With .Resize(IntV, 10)
             .FormatConditions.Add Type:=2, Formula1:="=GAUCHE($C7)=""C"""
             .FormatConditions(1).Interior.ThemeColor = 3
             .FormatConditions(.FormatConditions.Count).SetFirstPriority
         End With
         
        ' With .Resize(IntV, 10)
         '     .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
         'End With
         
         With .Resize(32, 10)
             .BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
             .Borders(xlInsideVertical).LineStyle = xlContinuous
         End With
         
     End With
 End With
 ' ---------------pour tenir compte des mois de 31 jours
 Range("B38:C38").HorizontalAlignment = xlCenterAcrossSelection
 Range("B38") = "Toto"
 Range("B38:k38").BorderAround xlContinuous, xlThick, xlColorIndexAutomatic
 End Sub

??? toujours le problème signalé au #32
 

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Bonsoir à tous

Modeste Geedee
J'ai replongé dans le bac de compactage ;)
(Quel est donc ce problème dont tu parles -> #32)
EDITION:
OK, je viens de capter -> C1048574
Je vais voir si je trouve une parade (ou une autre formule pour la MFC ou autre chose à la place de la MFC)

StrikeBEH
: Tu vois qu'on peut ne pas fusionner les cellules, avec un résultat visuel identique
Code:
Const sWd As String = "Heure"
Sub TestII()
Dim Form$, IntV&, arrSTR, i As Byte
arrSTR = Array("Date", "Type", sWd & " Début" & Chr(10) & "de Service", sWd & " Fin" & Chr(10) & "de Service", _
"Nb " & sWd & "s" & Chr(10) & "Travaillées", sWd & "s" & Chr(10) & "de jour", sWd & "s" & Chr(10) & "de nuit", _
sWd & "s" & Chr(10) & "à 150%", sWd & "s" & Chr(10) & "à 200%", sWd & "s" & Chr(10) & "Sam/Dim")
     
     With Range("B1:K4,B5:K5,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6")
        .BorderAround 1, 4, -4105: .Interior.Color = 39423
        .Font.Size = 9: .Font.Bold = True
        .HorizontalAlignment = -4108: .VerticalAlignment = -4108
     End With
    Range("B5") = StrConv(Format(Date, "mmmm yyyy"), vbProperCase)
    Range("B5:K5").HorizontalAlignment = 7
    For i = 0 To 9
    Cells(6, Chr(66 + i)) = arrSTR(i)
    Next i

 IntV = CLng(Day(DateSerial(Year(Date), Month(Date) + 1, 0)))
 Form = "DATE(YEAR(TODAY()),MONTH(TODAY()),ROW()-6)"
     With Range("B7")
     '-----------------------------------------------------
        .Resize(33, 10).Clear
     '-----------------------------------------------------
        With .Resize(IntV, 1)
            .HorizontalAlignment = xlCenter
             .VerticalAlignment = xlCenter
             .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
             .Value = .Value
         With .Offset(, 1)
             .HorizontalAlignment = xlCenter
             .VerticalAlignment = xlCenter
             .FormulaR1C1 = "=INDEX({""CC"";""JT"";""JT"";""JT"";""JT"";""JT"";""CR""},WEEKDAY(" & Form & "))"
             .Value = .Value
         End With
         With .Resize(IntV, 10)
             .FormatConditions.Add Type:=2, Formula1:="=GAUCHE($C7)=""C"""
             .FormatConditions(1).Interior.ThemeColor = 3
             .FormatConditions(.FormatConditions.Count).SetFirstPriority
         End With

         With .Resize(32, 10)
             .BorderAround 1, 4, -4105
             .Borders(11).LineStyle = 1
         End With

     End With
 End With
 ' ---------------pour tenir compte des mois de 31 jours
With Range("B38:C38")
    .Range("A1") = "TOTAUX": .BorderAround 1, 4, -4105: .HorizontalAlignment = 7
End With
End Sub
 
Dernière édition:

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

Bonjour,
Ayant pris un peu de temps pour étudier avec attention vos différents codes, car j'aime bien comprendre qui fait quoi... et pas me contenter d'adopter bêtement du code, j'ai fait un mixte du code de Modeste et de Staple, ce qui donne:
VB:
Option Explicit

Public MoisActuel As String
Public AnnéeActuelle As String
'Public i As Integer
Const sWd As String = "Heure"

Sub FeuilMoisActuel()
MoisActuel = Format(Date, "mmm yyyy")
AnnéeActuelle = Format(Date, "yyyy")
Application.ScreenUpdating = False

If Sheets(1).Name = "Feuil1" Then
'    Sheets(1).Name = MoisActuel
    Sheets(1).Tab.Color = 39423
    Columns("A:A").ColumnWidth = 2
    Columns("B:C").ColumnWidth = 4
    Columns("D:D").ColumnWidth = 10
    
    Columns("E:F").ColumnWidth = 8
    Columns("G:J").ColumnWidth = 6
    Columns("K:K").ColumnWidth = 8
    Columns("L:L").ColumnWidth = 2
    
    Rows("1:1").RowHeight = 12
    Dim CheminLogo As String
    CheminLogo = "C:\Logos\" & "TEC.jpg"
    ActiveSheet.Shapes.AddPicture CheminLogo, True, True, 15, 1, 383, 57
'    Identité.Show
    Range("B1:K4,B5:K5").MergeCells = True
     
    Dim Form$, IntV&, arrSTR, i As Byte
    arrSTR = Array("Date", "Type", sWd & " Début" & Chr(10) & "de Service", sWd & " Fin" & Chr(10) & "de Service", _
    "Nb " & sWd & "s" & Chr(10) & "Travaillées", sWd & "s" & Chr(10) & "de jour", sWd & "s" & Chr(10) & "de nuit", _
    sWd & "s" & Chr(10) & "à 150%", sWd & "s" & Chr(10) & "à 200%", sWd & "s" & Chr(10) & "Sam/Dim")
         
    With Range("B1:K4,B5:K5,B6,C6,D6,E6,F6,G6,H6,I6,J6,K6")
        .BorderAround 1, 4, -4105: .Interior.Color = 39423
        .Font.Size = 9: .Font.Bold = True
        .HorizontalAlignment = -4108: .VerticalAlignment = -4108
    End With
    
    Range("B5:K5").HorizontalAlignment = 7
    Range("B5") = StrConv(Format(Date, "mmmm yyyy"), vbProperCase)
    
    For i = 0 To 9
    Cells(6, Chr(66 + i)) = arrSTR(i)
    Next i
    
    IntV = CLng(Day(DateSerial(Year(Date), Month(Date) + 1, 0)))
    Form = "DATE(YEAR(TODAY()),MONTH(TODAY()),ROW()-6)"

    With Range("B7")
        .Resize(33, 10).Clear
        With .Resize(IntV, 1)
            .Font.Size = 9: .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
            .Value = .Value
           
        With .Resize(IntV, 10)
            .FormatConditions.Add Type:=2, Formula1:="=Droite($B7)=""S"""
            .FormatConditions.Add Type:=2, Formula1:="=Droite($B7)=""D"""
            .FormatConditions(1).Interior.ThemeColor = 3
            .FormatConditions(2).Interior.ThemeColor = 3
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
        End With

        With .Resize(IntV + 1, 10)
            .BorderAround 1, 4, -4105
            .Borders(11).LineStyle = 1
        End With
         
        With Range(Cells(IntV + 7, 2), Cells(IntV + 7, 5))
            .MergeCells = True
            .Value = "TOTAUX"
        End With
        
        With Range(Cells(IntV + 7, 2), Cells(IntV + 7, 11))
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .Font.Bold = True
            .Interior.Color = 39423
        End With
    End With
End With
    
    Dim Ddate As Long, Ddebut As Long, Dfin As Long, PAQ As Long
    Dim An As Integer, Dstat As String, Dcolor As Long
    An = Year(Date)
    
    PAQ = Evaluate("=DATE(" & An & ",3,29.56+0.979*MOD(204-11*MOD(" & An & ",19),30)- WEEKDAY(DATE(" & An & ",3,28.56+0.979*MOD(204-11*MOD(" & An & ",19),30))))")
    Ddebut = DateSerial(An, Month(Date), 1)
    Dfin = DateSerial(An, Month(Date) + 1, 0)
'    Range("B7:C37").ClearContents
    i = 1
    For Ddate = Ddebut To Dfin
    Select Case Ddate
        Case DateSerial(An, 1, 1) _
            , DateSerial(An, 5, 1) _
            , DateSerial(An, 7, 21) _
            , DateSerial(An, 8, 15) _
            , DateSerial(An, 11, 1) _
            , DateSerial(An, 11, 11) _
            , DateSerial(An, 12, 25) _
            , (PAQ + 1) _
            , (PAQ + 39) _
            , (PAQ + 50)
            With Range("C" & i + 6)
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlCenter
            End With
            Range("C" & i + 6) = "JF"
            Range("B" & i + 6, "K" & i + 6).Interior.Color = vbRed
        End Select
        i = i + 1
    Next Ddate
    
    Else
    For i = 1 To Sheets.Count
    If Sheets(i).Name = (MoisActuel) Then Exit Sub
    Next i
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Name = MoisActuel
    Sheets(MoisActuel).ScrollArea = "A1:Z120"
End If
End Sub
J'ai adapté les jours fériés car en France et en Belgique, ils ne sont pas tous identiques... et j'ai aussi supprimer le remplissage automatique de la colonne C car un jour de la semaine peut être un "CC".
A cet effet, afin de remplir le tableau, je vais créer un UserForm avec des cases à cocher pour renseigner "JT" ,"CC","CR".

Encore merci à vous pour votre aide et si, sans vouloir abuser, vous pouviez me faire part de vos impressions concernant mes modifs...
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Bonsoir à tous

StrikeBEH
Encore merci à vous pour votre aide et si, sans vouloir abuser, vous pouviez me faire part de vos impressions concernant mes modifs...
Tu as remis des cellules fusionnées!
Donc je garde le silence. ;)

PS: Tu n'avais pas lu cette remarque dans mon précédent message?
StrikeBEH: Tu vois qu'on peut ne pas fusionner les cellules, avec un résultat visuel identique
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Re

StrikeBEH
Je déteste plus encore les amis de Sigmund que les cellules fusionnées. ;)

Sérieusement, regardes sur le net, tu verras que je ne suis pas le seul à déconseiller l'usage des cellules fusionnées.

Mais au final, ce qui compte, c'est la dernière version de ton code VBA te satisfasse.
 

Discussions similaires

Réponses
5
Affichages
193

Membres actuellement en ligne

Statistiques des forums

Discussions
312 294
Messages
2 086 895
Membres
103 404
dernier inscrit
sultan87