Тёмный

Create a Pivot table with VBA in Excel 

Barb Henderson
Подписаться 37 тыс.
Просмотров 35 тыс.
50% 1

Create a Pivot table with VBA
Create a pivot table. Create a pivot table with a macro. Create a pivot table that you can reuse.
Sub pivottable()
Dim PSheet As Worksheet
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim PTable As pivottable
Dim PRange As Range
Dim LastRow As Long
Dim LastCol As Long
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("PivotTable").Delete
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "PivotTable"
Application.DisplayAlerts = True
Set PSheet = Worksheets("PivotTable")
Set DSheet = Worksheets("sheet1")
LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange). _
CreatePivotTable(TableDestination:=PSheet.Cells(2, 2), _
TableName:="PivotTable")
Set PTable = PCache.CreatePivotTable _
(TableDestination:=PSheet.Cells(1, 1), TableName:="PivotTable")
Sheets("PivotTable").Select
Sheets("PivotTable").Select
With ActiveSheet.PivotTables("PivotTable").PivotFields("salesperson")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable").PivotFields("type")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable").AddDataField ActiveSheet.PivotTables( _
"PivotTable").PivotFields("amount"), "Sum of amount", xlSum
End Sub
Click this link to check out my one-on-one training www.calendly.com/easyexcelanswers
For more help visit my website www.easyexcelanswers.com or email me at easyexcelanswers@gmail.com.
Contact me regarding customizing this template for your needs.
Click for online Excel Consulting www.calendly.com/easyexcelanswers
I am able to provide online help on your computer at a reasonable rate.
www.amazon.com/shop/barbhende...
I use a Blue condenser Microphone to record my videos, here is the link
amzn.to/37gyyGa
Check out Crowdcast for creating your webinars
app.linkmink.com/a/crowdcast/83
I use Tube Buddy to help promote my videos
Check them out
www.Tubebuddy.com/easyexcelan...
Follow me on Facebook
/ easyexcel.answers
TWEET THIS VIDEO
Follow me on twitter
easyexcelanswers
IG @barbhendersonconsulting
You can help and generate a translation to you own language
ru-vid.com_cs_p...
*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I've used or have experience with.
How to insert VBA code in Excel • How to insert VBA code...

Хобби

Опубликовано:

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@Christina-dm4ff
@Christina-dm4ff 5 лет назад
Thank you so much!! I think i can use your code to serve part of the function i need!! this is a very important piece. It would save me an hour doing it manually. thanks a million
@ChodeOReilly
@ChodeOReilly 5 лет назад
Thank you for this tutorial. It helped me tremendously.
@surangiweerakoon7447
@surangiweerakoon7447 5 лет назад
Thanks you so much,. Truly useful!
@diwakarpandey2507
@diwakarpandey2507 6 лет назад
Thanks Henderson ! It's really helpful !!!!!!!!!!!!!!!!!!!!!!
@gregarayamandelbrot
@gregarayamandelbrot 3 года назад
I had no idea you could do this, saving my skin. Thanks so much!
@BarbHendersonconsulting
@BarbHendersonconsulting 3 года назад
Glad I could help!
@elohan6082
@elohan6082 5 лет назад
fabulous solution and code, thanks so much
@achilleasmanousakis4622
@achilleasmanousakis4622 4 года назад
Thank you, very useful
@4511raj
@4511raj 4 года назад
good explanation
@ismailismaili0071
@ismailismaili0071 6 лет назад
so cool
@user-dp3jb1zj9l
@user-dp3jb1zj9l 3 года назад
Спасибо. Макрос помог мне сегодня. Все работает отлично.
@BarbHendersonconsulting
@BarbHendersonconsulting 3 года назад
пожалуйста
@RAEN74
@RAEN74 4 года назад
I know little so I can't critique, but I have to say you did this in what seems to be a great and simple way to perform this.
@JyotiSharma-ft3en
@JyotiSharma-ft3en 5 лет назад
Hello Mam, thanks for your video. But am not able to fetch my table data, as my data table start from row 6 to column S
@alishacrswartz
@alishacrswartz 3 года назад
excelchamps for the win
@BarbHendersonconsulting
@BarbHendersonconsulting 3 года назад
thanks
@mohamadismail9768
@mohamadismail9768 4 года назад
I am facing an error at "Set PCache". Please help.
@damienhettiarachchi9469
@damienhettiarachchi9469 Год назад
Why error message shows pivot table report will not fit on the sheet. Do you want to show as much as possible? Need to create pivot with 24 table columns Data sheet row count 600000
@BarbHendersonconsulting
@BarbHendersonconsulting Год назад
I was not aware that there was a limit to the size, but I guess there is
@damienhettiarachchi9469
@damienhettiarachchi9469 Год назад
@@BarbHendersonconsulting Thanks for the reply 🤝
@anjanikumar2708
@anjanikumar2708 2 года назад
Hi, this code is not running,
@BarbHendersonconsulting
@BarbHendersonconsulting 2 года назад
see my other reply
@anjanikumar2708
@anjanikumar2708 2 года назад
It shows error in PCache
@BarbHendersonconsulting
@BarbHendersonconsulting 2 года назад
try adding Dim pCache As PivotCache Dim pTable As PivotTable
@jomzrpg6312
@jomzrpg6312 4 года назад
This does not work in Excel 2016.
@BarbHendersonconsulting
@BarbHendersonconsulting 4 года назад
I created this in Excel 2016
@CyrrilE
@CyrrilE 4 года назад
@@BarbHendersonconsulting hi! I'm getting a type mismatch error along the lines re: setting the PCache rows.
Далее
Simple VBA Fixes for Excel PivotTable Macros
16:52
Просмотров 74 тыс.
Я НЕ ОЖИДАЛ ЭТОГО!!! #Shorts #Глент
00:19
Пиратские котики
00:50
Просмотров 55 тыс.
Create Pivot table with VBA Macro
10:37
Просмотров 29 тыс.
How to Filter a Pivot Table in Excel Using VBA
13:19
Просмотров 25 тыс.
How to use Power Pivot in Excel | Full Tutorial
30:38
Auto Refresh PivotTables & Queries - without VBA!
9:37
Excel VBA Macro to Create a PivotTable
7:40
Просмотров 47 тыс.
10X Your Excel with Macros & Basic VBA
11:18
Просмотров 79 тыс.
Simple pivot table using an excel macro
8:57
Просмотров 91 тыс.
3 Essential Excel skills for the data analyst
18:02
Просмотров 1,5 млн
Черёмуха во рту вяжет
0:11
Просмотров 1,6 млн