Ik wil aan het eind van een verdeelprogramma een overzichtje in een draaitabel laten zien. Als ik dit handmatig doe, werkt het precies en goed. Stop ik het maken van de draaitabel in onderstaande code, slaat ie het laatste team over. Hoe kan dat?
Programmacode:
Je ziet dat ik verschillende manieren van selecteren heb geprobeerd.
Bijgevoegd het voorbeeldsheet waarop deze code moet draaien.
Programmacode:
Code:
Public Sub MaakBladAf()
Dim laatsteCel
Dim Rij As Integer
Dim Kolom As Integer
Dim rString As String
Blad4.Activate
Let laatsteCel = Blad4.Range("A65500").End(xlUp).Row
Let rString = "A1:" + "G" + CStr(laatsteCel)
Blad4.Range("A1:G600").Select
' Let Rij = 1
' Do While Rij <= laatsteCel + 1
' For Kolom = 1 To 7
' Blad4.Cells(Rij, Kolom).Select
' Next Kolom
' Let Rij = Rij + 1
' Loop
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Gebruikers!R1C1:R81C7").CreatePivotTable TableDestination:= _
"'[Verdeeltool claim XP.xls]Gebruikers'!R5C9", TableName:="Draaitabel4", _
DefaultVersion:=xlPivotTableVersion10
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("Draaitabel4").PivotFields("Team")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("Draaitabel4").AddDataField ActiveSheet.PivotTables( _
"Draaitabel4").PivotFields("Aantal"), "Aantal van Aantal", xlCount
With ActiveSheet.PivotTables("Draaitabel4").PivotFields("Aantal van Aantal")
.Function = xlSum
.NumberFormat = "0"
End With
ActiveSheet.PivotTables("Draaitabel4").PivotSelect "'(blank)'", xlDataAndLabel _
, True
Selection.Delete
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Let Blad4.Cells(16, 9).FormulaR1C1 = "Rest = "
Let Blad4.Cells(16, 10).FormulaR1C1 = "=R[7]C"
Blad4.Cells(23, 10).Font.ColorIndex = 2
Blad4.Cells(24, 10).Font.ColorIndex = 2
End Sub
Je ziet dat ik verschillende manieren van selecteren heb geprobeerd.
Bijgevoegd het voorbeeldsheet waarop deze code moet draaien.