VBA - Pivot table creation- Edit code

anna99

New Member
Joined
Jan 8, 2021
Messages
19
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:

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,070
Office Version
  1. 2016
Platform
  1. Windows
Sheets(myws).Select ==>myws.Select
 

Watch MrExcel Video

Forum statistics

Threads
1,128,167
Messages
5,629,079
Members
416,364
Latest member
maatpsr

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
Top