Thanks for the quick return!
Btw, Excel version is 2010.
I followed what you guys said. Select entire PT -> (go back to Select dropdown again) select Values (because I only want DataRange to have shade) -> Design, trying to pick PivotTable Styles (similar to Format as Table) but nothing happens.
The following is the code I set up to serve the same purpose, with the help of CF. It works. But if I could have it done without the macros, I would remove the code and let the Excel built-in functionality handle the situation.
Thanks again.
Sub PTViaADO_0902()
Dim Con As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim sql As String
Dim PTCache As PivotCache
Dim pt As PivotTable
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\DATA\FED_CHARGEBACK.mdb;"
sql = "SELECT * FROM FED_REPORT_FINAL_CITYST "
sql = "SELECT Customer, [Cust Name], [Cust City], [Cust State], [Cust Nmbr],PRODUCT, st, MONTH, [WAC SALES], [RAW UNITS], NET " & _
"FROM FED_REPORT_FINAL_CITYST"
Set RS = New ADODB.Recordset
Set RS.ActiveConnection = Con
RS.Open sql
On Error Resume Next
Sheets("Sheet1").UsedRange.Clear
On Error GoTo 0
'Create the PivotTable cache....
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
Set PTCache.Recordset = RS
Set pt = PTCache.CreatePivotTable _
(TableDestination:=Sheets("Sheet1").Range("a2"), _
TableName:="one")
With pt
.AddFields PageFields:=Array("Cust City", "Cust State", "Cust Name", "Customer")
.PivotFields("PRODUCT").Orientation = xlRowField
With .PivotFields("MONTH")
.Orientation = xlColumnField
.NumberFormat = "mmm-yy"
End With
With .PivotFields("NET")
.Orientation = xlDataField
.Function = xlSum
.Caption = "Feder Net Sales"
.NumberFormat = "$#,##0"
End With
End With
Call cf
Sheets("Sheet1").Activate
End Sub
Sub cf()
Dim pt As PivotTable
Dim combo As Range
Sheet10.Activate
Set pt = ActiveSheet.PivotTables(1)
Set combo = Union(pt.RowRange, pt.DataBodyRange)
combo.Select
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0"
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.349986266670736
End With
End With
pt.PivotSelect "", xlDataAndLabel, True
Selection.Style = "Input"
Range("A8").Select
End Sub
Sub cleargarb()
srow = Cells(1, 1).PivotTable.TableRange1.Row
erow = Cells(srow, 1).End(xlDown).Row
Range(Cells(erow + 1, 1), Cells(1000, 27)).Clear
scol = Cells(1, 1).PivotTable.TableRange1.Column
ecol = Cells(1, 1).PivotTable.TableRange1.Columns.Count
Range(Cells(1, ecol + 1), Cells(1000, ecol + 100)).Clear
End Sub
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Application.ScreenUpdating = False
Call cf
Call cleargarb
Application.ScreenUpdating = True
End Sub