Results 1 to 9 of 9

Pivot Table VBA code: Out of Range Error

Threaded View

  1. #1
    Registered User
    Join Date
    02-16-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Pivot Table VBA code: Out of Range Error

    Hi Guys,

    I need to automate pivot table creation through VBA, and I have hit a bit of snag that I am hoping some of you may help me out with.
    The following code is used:
    '
    ' Pivot_Table Macro
    '

    '
    Worksheets("Summary Sheet").Activate
    Worksheets("Summary Sheet").Select
    Range("A5").Select
    ActiveWorksheets.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Sheet1!R5C1:R34665C4", Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:="Summary Sheet!R5C1", TableName:="PivotTable1", _
    DefaultVersion:=xlPivotTableVersion14
    Sheets("Summary Sheet").Select
    Cells(5, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("DDDD")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("DDDDD1")
    .Orientation = xlRowField
    .Position = 2
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("DDDD111")
    .Orientation = xlRowField
    .Position = 3
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("Dialled_Number_Name"), _
    "Count of Dialled_Number_Name", xlCount
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("DDDDD111")
    .Orientation = xlColumnField
    .Position = 1
    End With
    Now I am having the following error at the following line: Runtime error 1004 Select Method of Range Class failed.

    And it occurs at the following:

    Range("A5").Select
    Can you guys figure out what is wrong with the code, the macro was recorded while I made the pivot table.
    Last edited by AmmonRA; 02-17-2011 at 08:02 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1