i cant define sourcedata for vba - vba

I am trying to create a pivot table using vba. My first step is to create pivotcaches. I dont know what to do with sourcedata. I looked up online, people are using like SourceData:=
"Sheet1!R1C1:R4C3". I can not do it because i have to update worksheet everyday and i have thousands of rows and columns. i am thinking to do like ctrl + a (select all the regions) but i dont know what to do and i tried sourcedata:= sheets("nameofmysheet").range("a2"),currentregion. it wont work either. i dont know what to do now. Help me!

Best advice? Record a macro when you create a pivot table and then look at the code generated by Macro 😊 This way you can experiment and create various pivots from various sources. It will help you understand the process.

Related

Dictionary vs pivot Table and some office issues

In company when I currently work we have big issue with MS excel stability, hence my question below.
Recently I just learned about excel Dictonary code.
I know pivot tables and how they work.
sadly the issue is not with pivot themselves but with excel. (IT dept. is working on the issue for 3 weeks now, and we dont know when / if they gonna fix it)
Hence my big ask for thi community:
I would need a userform working with the dictonary.
What I would need is to create a code that could work as pivot table but using dictonaries (since theoreticaly they are faster and are outside of VBA / excel basic in-build option)
so?
Can some1 help in creating such code?
Is this the right option?
I would like to see a userform where I can choose my Table(ctrl+T) headers to choose by which header i want to sum values up, and ofc I would have to be able to choose a column by which the dictonary summing is working on.
Thank you both for answering.
Lets start then.
I watched ExcelMacroMastery videos regarding dictionaries,
In this example, he used them to make a basic sum exactly like the basic functionality of Pivot table.
So since that's the basic use where I work I wish to have a dictionary macro from which I can choose the column by which I get unique values and 2nd column with a sum from the second provided column from a table.
the issue is: if I show any file or any example this could result in macro working for this specific case, and I would like it to be able to choose by Table's (CTRL+T) headers for the unique values and to use some way(like a dropdown menu) to choose the column by which the sum can happen.
This instability is due to 32 bit office suite 365 working n 64 bi PCs/ laptops and recent company update made it even worse, now there is an issue with even basic save file option.
Not to mention excel crashing for no apparent reason.
So to sum up,
I need dictionaries to kinda step up and replace basic summarizing functionality of an pivot table.
or to replace this non pivot way:
use unique function to determine unique values from specified column (non-table object sadly)
Use sumif or sumoifs function to summarize the specified amount/value for that unique list.
//EDIT:
I kinda found what I was looking for thus the edit.
Im showing the link to the file I wish to change a bit:
https://app.monstercampaigns.com/c/s0iavndiopijkrar8ghp/
to this file I wish to add a user form by which the headers of the report will be chosen from source data, and by which the sum will occur.

Equivalent of .ShowDetail in google apps script

Trying to write a Google apps-script to show details from a pivot table in google sheets.
In vba I would loop through the range of values in the pivot table and use Range(XYZ).ShowDetail = True to create separate sheets of the underlying data - I can right click each value in a pivot in google sheets and select Show Details - I want this done via script.
Any help is much appreciated.
Currently, there doesn't seem to be a equivalent way to create sheets from pivot table programmatically. Consider creating a feature request in the issue tracker

Identify Pivot Field using VBA

I am trying to write a macro which automatically identifies which field is the data taken from in a pivot.
I have some columns with different level of org information dragged under one another in "Row Labels" to create a structure. Now I need to identify which row in the pivot is linked to which field.
I am a self-taught coder and am very new to advanced vba so need some help.
How my pivots look
I am trying to get the name of the field in the blue circle
Thank you!
Nevermind guys, It was simpler than I thought. I am just an idiot for not figuring it out earlier.
Anyhow, the solution is that "ActiveCell.PivotField" returns the Pivot row's field.

Use VBA to get row data from powerpivot data?

I have imported a table in powerpivot, and were wondering if it's possible to get a row data from that source, by using VBA?
Lets say I import a table to my powerpivot datamodel from an external source, that looks like below:
col1 col2
1 tt
2 tg
As the data is not on any sheet, but in the datamodel. Can I treat this datamodel table like an ordinary table with VBA. e.g. get a specific row or sum a column?
I have tried searching alot for this, but google results and excel seems to me abit messy. I have little experience in VBA, and basically have to idea how/if this is possible.
You can reference the DataModel using CUBE functions, which can be called by VBA if you like. For examples, see https://powerpivotpro.com/2010/06/using-excel-cube-functions-with-powerpivot/
But the question is, why would you want to? To some degree, PowerPivot and the DataModel were designed to let you do complicated things right out of the box with little knowledge of code, instead of having to resort to VBA. Instead, just write whatever measures or calculated columns you need, and bring them into the worksheet via a PivotTable.
Well, you didn't give a lot of details around what you are doing, but I think the script below will be a good place to start. modify to suit your needs.
Sub blah()
Set pt = ActiveSheet.PivotTables(1)
Set pits = pt.PivotFields("???").PivotItems
For Each pit In pits
If pit.Visible Then 'only acts on visible items
pit.DataRange.ShowDetail = True
'pit.name 'contains pivot item name that you could use to refer to a workbook to copy the data on the active sheet to, eg.;
'ActiveSheet.ListObjects(1).DataBodyRange.Copy Workbooks(pit.Name).Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1)
End If
Next pit
End Sub

Using an Excel macro to query a spreadsheet

So I have some data in some spreadsheets and I've found that for all the macros and filtering and forumlas I've written to simplify it and narrow it down to what I want, it would have been much easier to just write some SQL against a few tables.
I guess I'm wondering: is it possible to have a macro in a workbook that queries data in some sheets and then populates another sheet with the result set? If so, how would I do it?
(It is Excel 2003)
No need for a macro for this.
Go to DATA-> Import External Data -> Import Data then basically follow the prompts. You may need to make a new data connection, (New Source at the bottom) but once connected you can write queries natively in Excel.
I'm guessing someone familiar with DBs would be able to figure it out pretty quickly. If not, here's a tutorial.
Why do you need to use a macro when you can simply query the excel file like this:
SELECT Column1, Cloumn2, Column3
FROM [SheetName$Range]
WHERE Condition
Example:
SELECT ProductID, Qty, Price
FROM [SheetName$A10:C21]
WHERE ProductID = 545