Consulting

Results 1 to 4 of 4

Thread: Runtime error at #dataname = ActiveSheet.ListObject(1).Name#

  1. #1
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location

    Runtime error at #dataname = ActiveSheet.ListObject(1).Name#

    Hi - while executing macro, i receive a runtime error at
    #dataname = ActiveSheet.ListObject(1).Name#
    any suggestions?

    Below is the script:
    ============================================
    #
    Sub testingmacro()
    '
    ' testingmacro Macro
    ' For Pivot
    '


    '


    Dim dataname As String
    Dim newsheet As String




    Columns("A:O").Select

    dataname = ActiveSheet.ListObject(1).Name

    Sheets.Add
    newsheet = ActiveSheet.Name

    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    dataname, Version:=6).CreatePivotTable TableDestination:= _
    newsheet & "!R3C1", TableName:="PivotTable1", DefaultVersion:=6
    Sheets(newsheet).Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("request.u_campaign")
    .Orientation = xlPageField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("assignment_group")
    .Orientation = xlRowField
    .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("number"), "Count of number", xlCount
    End Sub
    #
    =====================================================

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    dataname = ActiveSheet.ListObjects(1).Name
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Jul 2009
    Posts
    58
    Location
    Thank-you p45cal. However, i'm still facing the same error.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    A guess (more info needed):
    Sub testingmacro()
    Dim dataname As String
    Dim newsheet As String
    
    Columns("A:O").Select
    
    dataname = ActiveSheet.ListObjects(1).Name
    
    Sheets.Add
    newsheet = ActiveSheet.Name
    
    With ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=dataname, Version:=6).CreatePivotTable(TableDestination:=newsheet & "!R3C1", DefaultVersion:=6)
      With .PivotFields("request.u_campaign")
        .Orientation = xlPageField
        .Position = 1
      End With
      With .PivotFields("assignment_group")
        .Orientation = xlRowField
        .Position = 1
      End With
      .AddDataField ActiveSheet.PivotTables("PivotTable1").PivotFields("number"), "Count of number", xlCount
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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