I'm creating a PivotTable in Excel using VBA. One of the fields is a time value (formatted as "hh:mm:ss"), and I want the row labels to show each hour (e.g., 00:00, 01:00, 02:00), not every minute.
Here's the relevant part of my code:
With ptHour
' Filtros
.PivotFields("Vehicle id").Orientation = xlPageField
.PivotFields("Type").Orientation = xlPageField
.PivotFields("Confirmation").Orientation = xlPageField
.PivotFields("Fecha").Orientation = xlColumnField
.PivotFields("hour").Orientation = xlRowField
.AddDataField .PivotFields("Vehicle id"), "count of Vehicle ID", xlCount
On Error Resume Next
.PivotFields("hour").LabelRange.Group _
Start:=TimeValue("00:00:00"), _
End:=TimeValue("23:59:59"), _
By:=TimeValue("01:00:00")
On Error GoTo 0
End With
The source data in column K is formatted as "hh:mm:ss" using:
wsGuardian.Range("K6:K" & LastFila).NumberFormat = "hh:mm:ss"
However, the PivotTable still shows every minute (e.g., 08:01, 08:02, etc.) instead of grouping by hour.
