XL 2016 Formule dans tdc [Résolu]

BBdoc31

XLDnaute Nouveau
Bonjour à tous !

Voilà j'ai un petit soucis, je n'arrive pas à borner mon tableau dynamique croisé avec une valeur issue d'une formule

exemple
Dim drLig As Long

drLig = Range("A" & Rows.Count).End(xlUp).Row

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Matelas!R1C1:R5000C6", Version:=6).CreatePivotTable TableDestination:= _
"Matelas!R1C8", TableName:="Tableau croisé dynamique3", DefaultVersion:=6
Sheets("Matelas").Select

Je voudrais remplacer le 5000 par drlig mais je n'y arrive pas
J'ai testé "Matelas!R1C1:R"" & drLig & ""C6" marche pas !

Je pèche un peu dans la formulation à mettre " ou "" ?
Ou c'est impossible ?
 

Jean-Eric

XLDnaute Occasionnel
Bonjour,
Une proposition à étudier.
Cdlt
VB:
Option Explicit

Public Sub Create_PT()
'Déclaration des variables
Dim wb As Workbook
Dim wsData As Worksheet
Dim PTCache As PivotCache
Dim pt As PivotTable
    'Optimisation (gel affichage)
    Application.ScreenUpdating = False
    'Initialisation des variables
    Set wb = ActiveWorkbook
    Set wsData = wb.Worksheets("Matelas")
    'Création cache (source des données)
    Set PTCache = wb.PivotCaches.Create(xlDatabase, wsData.Cells(1).CurrentRegion)
    'Création tableau croisé dynamique (TCD)
    Set pt = PTCache.CreatePivotTable(wsData.Cells(1, 8), "TCD_1")
    With pt
        .ManualUpdate = True
        'Code
        '
        '
        .ManualUpdate = False
    End With
    'RAZ variables
    Set pt = Nothing
    Set PTCache = Nothing
    Set wsData = Nothing
    Set wb = Nothing
End Sub
 

BBdoc31

XLDnaute Nouveau
Merci pour la solution
Code:
    Set Rng = Range("A1:F" & drLig)
        ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Rng, _
        Version:=6).CreatePivotTable TableDestination:= _
        "Matelas!R1C8", TableName:="Tableau croisé dynamique3", DefaultVersion:=6
Voilà le code adapté pour mon excel.

Encore merci pour cette épine enlevé du pied
 

Discussions similaires

Réponses
1
Affichages
515