Bonjour,

Je souhaite grouper automatiquement les dates que j'ai en trimestre: J'ai des date allant de 2015 jusqu'en 2018.
Je veux grouper en trimestre que les dates de 2017.
Par exemple je vais avoir ce genre:
<2017, Q1, Q2, Q3, Q4, >2017
j'ai pu grouper tout automatiquement, mais la date automatique est par défaut la première date de ma liste donc 2015 et la dernière est 2018.
alors dans ce cas je modifie le champ manuellement!

Comment je peux faire? je veux pas la date automatique de defaut, mais comment choisir la date début :01/01/2017 et fin : 31/12/2017? je peux le faire manuellement mais j'ai bcp de tableaux, je préfère avec le code VBA

voici le code que j'utilise:

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
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 CreatePivotTableCompte()
'PURPOSE: Creates a brand new Pivot table on a new worksheet from data in the ActiveSheet
 
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
Dim y As Workbook
 
Set y = Workbooks.Open("Z:\Base_de_données\Base_Para.xlsx")
'Determine the data range you want to pivot
  lastrow = y.Sheets("TbCrx").Range("C" & Rows.count).End(xlUp).Row
  SrcData = y.Sheets("TbCrx").Name & "!" & Range("B1:F" & lastrow).Address(ReferenceStyle:=xlR1C1)
 
'Open a new worksheet
  Set sht = y.Sheets("Compte")
 
'Where do you want Pivot Table to start?
  StartPvt = sht.Name & "!" & sht.Range("A3").Address(ReferenceStyle:=xlR1C1)
 
'Create Pivot Cache from Source Data
  Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
    SourceType:=xlDatabase, _
    SourceData:=SrcData)
 
'Create Pivot table from Pivot Cache
  Set pvt = pvtCache.CreatePivotTable( _
    TableDestination:=StartPvt, _
    TableName:="PivotTable1")
 
 pvt.AddDataField pvt.PivotFields("Montant Final"), , xlSum
 pvt.AddDataField pvt.PivotFields("Montant Tarif"), , xlSum
  'Add item to the Column Labels
    pvt.PivotFields("M/Y").Orientation = xlColumnField
 
  'Add item to the Row Labels
    pvt.PivotFields("Compte").Orientation = xlRowField
 
  'Position Item in list
    pvt.PivotFields("M/Y").Position = 1
 
    sht.PivotTables("PivotTable1").PivotFields("Somme de Montant Final").Caption = ChrW(931) & "Mnt Final"
    sht.PivotTables("PivotTable1").PivotFields("Somme de Montant Tarif").Caption = ChrW(931) & "Tarif"
 
 
 'Group Date Field by Month and Year
 
pvt.RowAxisLayout xlTabularRow
Set df = pvt.PivotFields("M/Y")
df.LabelRange.Group _
'j'ai mis False car je veux pas la date automatique, mais comment choisir la date début :01/01/2017 et fin : 31/12/2017?
Start:=False, End:=False, by:=3, Periods:=Array(False, False, False, False, False, True, False)
df.Caption = "Trimestre"
 
lastrow2 = y.Sheets("Compte").Range("A" & Rows.count).End(xlUp).Row
y.Sheets("Compte").Range("B6:O" & lastrow2).Style = "Currency"
 
Set sht = y.Sheets("Compte")
sht.Range("B4:J4").replace What:="Trimestre", Replacement:="Q", _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
 
y.Close savechanges:=True
MsgBox ("Task Complete")
 
End Sub
merci d'avance pour vos aides!
cheers!