VBA - Pivot table creation- Edit code

anna99

New Member
Joined
Jan 8, 2021
Messages
26
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Could you please help, what is wrong with my code below, i try to use dynamic range and create a new worksheet (any) for pivot table doesn't matter it's sheet 2,3,4...in this workbook
thanks in advance



VBA Code:
Sub SURVEY()
Dim LR As Long, LC As Long, myrange As Range, myws As Worksheet

LR = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
LC = Sheet1.Cells(1, Columns.Count).End(xlToLeft).Column
Set myrange = Sheet1.Cells(1, 1).Resize(LR, LC)
Set myws = Worksheets.Add
'BELOW PART HAS ERROR 1004
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        myrange, Version:=6).CreatePivotTable TableDestination:= _
        myws.Cells(1, 1), TableName:="PivotTable1", DefaultVersion:=6
    Sheets(myws).Select
    Cells(1, 1).Select
    With ActiveSheet.PivotTables("PivotTable1")...............................................
 
Last edited by a moderator:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top