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,
 

Roland_M

XLDnaute Barbatruc
Re : Affichage format date

bonsoir,

@ Staple
En soi, cela ne change pas grand chose...

D'ailleurs pourquoi cette phobie des cellules fusionnées ? ;)

mais enfin Strike...!
des cellules fusionnées ne posent pas particulièrement de problème
tant que celles-ci ne trouvent pas dans un champ de données à traiter !

si tu avais plus d'expérience du comprendrais pourquoi !

et avec ces deux personnages, crois moi, tu devrais plutôt les écouter ça te permettrais d'évoluer !
 
Dernière édition:

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

@ Roland_M

Bonjour,
Justement il se trouve que les cellules fusionnées ne rentrent pas dans le champ des données à traiter, elles servent juste à inscrire des "légendes" style Totaux"...

De plus, je n'ai jamais caché que je n'avais pas l'expérience de "ces deux personnages" mais j'ai à maintes reprises répété que je les remerciais pour leur aide apportée et que même si je ne comprenais pas tout dans un premier temps, j'essayais d'étudier leurs propositions afin d'évoluer !!!
Je n'ai pas la prétention de tout connaitre loin de la et je le revendique...
Donc pour en revenir au débat des cellules fusionnées, le sujet est clos, non ?
 

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

Re et sans rancune...
Comprendras qui veut... (Je n'ai pas dit qui peut !) ;)

Si je peux me permettre encore de vous solliciter...
J'aimerai à partir de mon code, faire les calculs suivants:

En Colonne F7 à F28 (ou F30, F31, en fonction du nombre de jours par mois) avoir la soustraction de E7 D7 avec comme format sur la colonne F "[hh] h mm"

Les jours de nuit vont de 6h00 à 22h00 mais et une journée de travail peut commencer à 3h30 et se terminer à minuit !

Code:
Option Explicit

Public MoisActuel As String
Public AnnéeActuelle As String
Public Dépôt As String, NOM As String, Prénom As String, Matricule As String, National As String
Public DateSelect As String
Const sWd As String = "Heure"

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

    Dim i&
    For i = 1 To Sheets.Count
    If Sheets(i).Name = (MoisActuel) Then
        Exit Sub
        Else
        If Sheets(i).Name = "Feuil" & i Then
            Sheets(i).Tab.Color = 39423
''            Sheets(i).Name = MoisActuel
        End If
        If Sheets(Sheets.Count).Name <> MoisActuel Then
''            Sheets.Add After:=Sheets(Sheets.Count)
''            Sheets(Sheets.Count).Tab.Color = 39423
''            Sheets(Sheets.Count).Name = MoisActuel
''            Identité.Show
            Exit For
        End If
    End If
    Next i
    Columns("A:A").ColumnWidth = 2
    Columns("B:C").ColumnWidth = 4
    Columns("D:F").ColumnWidth = 11
    Columns("G: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,M2:N2,O2:P2,M3:N3,O3:P3,M4:N4,O4:P4,M5:N5,O5:P5,M6:N6,O6:P6").MergeCells = True
    With Range("M2:N6")
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlCenter
        .Font.Bold = True
    End With
    With Range("O2:P6")
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlCenter
        .Font.Bold = True
    End With
        
    Range("M2") = "Dépôt de "
    Range("M3") = "Chauffeur "
    Range("M4") = "Matricule "
    Range("M5") = "Numéro National "
    Range("M6") = "Embauché(e) le "
    Range("O2") = Dépôt
    Range("O3") = Prénom & " " & NOM
    Range("O4") = Matricule
    Range("O5") = National
    Range("O6") = DateSelect
    
    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 = 10: .Font.Bold = True
        .HorizontalAlignment = -4108: .VerticalAlignment = -4108
    End With
    
    Range("B5:K5").HorizontalAlignment = 7
    Range("B5") = StrConv(Format(Date, "mmmm yyyy"), vbUpperCase)
    
    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 = 10: .Font.Bold = True
            .HorizontalAlignment = xlCenter: .VerticalAlignment = xlCenter
            .FormulaR1C1 = "=TEXT(" & Form & ",""jj"")&MID(""DLMMJVS"",WEEKDAY(" & Form & "),1)"
            .Value = .Value
                  
        With .Offset(, 1)
            .Font.Size = 10: .Font.Bold = True
            .HorizontalAlignment = xlCenter: .VerticalAlignment = xlCenter
            .Value = "CC"
        End With
   
        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, 10)
            .BorderAround 1, 4, -4105: .Borders(11).LineStyle = 1
            .Borders(3).LineStyle = 1
        End With
         
        
        With Range(Cells(IntV + 7, 2), Cells(IntV + 7, 11))
            .BorderAround 1, 4, -4105: .Borders(11).LineStyle = 1
            .HorizontalAlignment = xlCenter: .VerticalAlignment = xlCenter
            .Font.Bold = True: .Font.Size = 10: .Interior.Color = 39423
        End With
        
        With Range(Cells(IntV + 7, 2), Cells(IntV + 7, 5))
            .MergeCells = True
            .Value = "TOTAUX"
        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
 

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Bonjour à tous

StrikeBEH
Si je peux me permettre encore de vous solliciter...
J'aimerai à partir de mon code, faire les calculs suivants:
Si je peux me permettre, il serait peut-être souhaitable pour la lisibilité du fil de ne pas fusionner ta dernière question avec celle qui initia le fil.
Cela n'a plus rien à voir (le titre était: Affichage Format date)
Tu devrais ouvrir une nouvelle discussion pour cette nouvelle question.
En tout cas, c'est ce que je suggère.

Pour infos: les deux codes ci-dessous pourraient être fusionné pour n'en faire qu'un seul.
With Range("M2:N6")
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
.Font.Bold = True
End With
With Range("O2:p6")
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.Font.Bold = True
End With

Sur ces derniers conseils, je vais étendre ma lessive, en écoutant un peu de jazz fusion, tout en vapotant un peu cet Urban Fusion (aujourd’hui, je vais me laisser tenter par le flacon Malicorne)


 
Dernière édition:

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

Effectivement, on peut "fusionner" ! ;) Mais comment puisque l'alignement horizontal est différent...
Merci pour ta remarque pertinente !

Quant au reste, je vais ouvrir une nouvelle discussion...
 
Dernière édition:

StrikeBEH

XLDnaute Occasionnel
Re : Affichage format date

@ Staple
Pourquoi dans le code suivant:

Code:
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)
''       With .Resize(32, 10)
             .BorderAround 1, 4, -4105
             .Borders(11).LineStyle = 1
'             .Value = "Totaux"
'            .Resize(1, 2) = "Totaux"
         End With
         
        With Range(Cells(IntV + 7, 2), Cells(IntV + 7, 5))
            .MergeCells = True
'             .HorizontalAlignment = xlCenter
'             .VerticalAlignment = xlCenter
'            .Font.Bold = 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


tu ne mets pas le End With après .Value = .Value

Est-ce un oublie ou cela a une répercution ???

Merci,

Suite... c'est bon, j'ai compris !
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Affichage format date

Re

Est-ce un oubli ou cela a une répercussion ???
Bah! pour le savoir, mets un End With et testes le code.
puis retire le End With et à nouveau, testes le code.
Y-a-t-il une différence ?

NB: je crois pouvoir dire qu'il s'ag

Sinon par rapport à ce que je disais précédemment voici comment je réduirais ton code.
Code:
With Range("M2:N6")
    .HorizontalAlignment = xlRight
    .Offset(, 2).HorizontalAlignment = xlLeft
With .Resize(, 4)
    .VerticalAlignment = xlCenter
    .Font.Bold = True
End With
End With
 
Dernière édition:

Discussions similaires

Réponses
5
Affichages
193

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

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