Also, if your range is bounded by any combination of blank rows and blank columns, you can define the range for your source data using the CurrentRegion property. So your code can be re-written as follows...
Code:
Dim rngSourceData As Range
Set rngSourceData = Worksheets("Invoice").Range("C13").CurrentRegion
Worksheets("Pivot").PivotTables("PivotTable1").ChangePivotCache _
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngSourceData)
[/QUOTE]
Hi Sir,
No, my range is not having Blanks .. but i have tried your 3rd code and it is working fine .. now my code is as below .... if still any correction required , plz advice me
Sub Pivot_Testing()
Sheets("Invoice").Select
Range("C13").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Dim rngSourceData As Range
Set rngSourceData = Worksheets("Invoice").Range("C13").CurrentRegion
Worksheets("Pivot").PivotTables("PivotTable1").ChangePivotCache _
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngSourceData)
Worksheets("Pivot").PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngSourceData, Version:=xlPivotTableVersion15)
Sheets("Pivot").Select
Range("A6").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub