Posts

Showing posts from September, 2023

Excel VBA Get DATA RANGE ONLY of HEADER

' ''Pivot Header Field Data Range Function PHFDR ( TableID As Variant ) As Variant () ''returns all headers from the table point to table or call by name Dim objPivot As PivotTable Dim x On Error GoTo SetErr Select Case LCase ( TypeName ( TableID ))               ''Takes pivot(any cell) or name Case "range" Set objPivot = TableID.PivotItem.Parent ''check if table name exists Case "string" Set objPivot = Application.Caller.Worksheet.PivotTables ( TableID ) End Select ''Data range of column header PHFDR = objPivot.ColumnRange.PivotField.DataRange     ''set header.data range Exit Function SetErr : PHFDR = CVErr ( xlErrNA ) ''failed to find/set pivot table End Function