PowerPivot Drill Through Formatting - powerpivot

Does anyone know a way to carry formatting through in a PowerPivot drill through? Whenever I do Drill Throughs on a PowerPivot workbook the report generated does not have the formatting set in PowerPivot, it just has the raw formatting from the table.

For changing the default table colors do this:
Double click to drill down and view the page.
Your tab now says Table Tools..
In Table Styles group click the lower right drop down button to view all styles
At the bottom see "New Table Style..."
Find the check box at the bottom of this dialog (New Table Quick Style) "Set as default table quick style for this document"
You'll have to use macros if you want to do anything else, this how I have accomplished column hiding in the past:
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Me.PivotTables("PivotTable1") ' replace with your PT name (see in pivot table options)
For Each pf In pt.PivotFields
If pf.Name = "Field1" Then ' change this to your field name
For Each pi In pf.PivotItems
pi.ShowDetail = True ' True to show, False to Hide
Next pi
End If
Next pf
Another way to accomplish this via macro is putting something like this in the workbook module:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
ans = MsgBox("Format this sheet?", vbYesNo)
If ans = vbYes Then blahh Sh
End Sub
Then put this in the tandard code module:
Sub blahh(sht As Worksheet)
MsgBox "formatting new sheet: " & sht.Name
End Sub
Tested and works with a pivot table, Excel 2007 already adds some styling to the drill down sheet.

Related

Clicking a hyperlink in Excel to set an auto filter on a different sheet

I have a detailed product order worksheet example table 2. and a summary worksheet supplier name and total value example Table 2.
I want to know is it possible when I click the hyperlink details will filter my detailed product order sheet under this supplier all order example table 3.
If anyone can do this for me it will be helpful for me
Table 1
Table 2
Table 3
You can use the Worksheet_FollowHyperlink event to detect when a hyperlink has been pressed. A hyperlink to a location within the document will have a SubAddress, and the text that you clicked on will be the TextToDisplay.
The following code will detect when you click a hyperlink to a worksheet and - if that worksheet has an autofilter - will filter the first column of the AutoFilter for the text that you clicked on.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim wsToFilter As Worksheet
On Error GoTo SubErr
If Right(Target.SubAddress, 3) = "!A1" Then 'Hyperlink is to a worksheet within this document
Set wsToFilter = ThisWorkbook.Worksheets(Replace(Target.SubAddress, "!A1", ""))
If wsToFilter.AutoFilterMode Then 'Hyperlink has an AutoFilter
wsToFilter.AutoFilter.ShowAllData 'Remove existing filters
wsToFilter.AutoFilter.Range.AutoFilter 1, Target.TextToDisplay 'Filter the First column for the text of the hyperlink
End If
Set wsToFilter = Nothing
End If
SubErr:
End Sub
Use the Worksheet.FollowHyperlink Event to filter the desired data.
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
MsgBox Cells(Target.Parent.Row, "A") 'returns the value of column A of the clicked link
'do your filter stuff here …
End Sub

Disable alert when manually deleting a sheet

Is there a way in VBA to disable the alert that pops up when MANUALLY deleting a sheet (right click sheet and delete)? I have seen Application.DisplayAlerts = False, however this seems to only work for me when deleting a sheet using VBA (Sheets("Sheet1").delete). I am trying to disable the alert for the whole workbook when you manually right click on a sheet and click delete. Thanks.
In case anyone else is looking for the same scenario:
...eliminate the need to confirm deleting a sheet when presenting the
workbook in meetings. While going through the sheets I often double
click on pivot tables to view detail, and I would like to eliminate
the pop-up alert when I delete the generated sheet...
If new sheets are generated only when double-clicking a pivot table, this might be a suitable solution
Placed in ThisWorkbook, the code bellow will delete any new sheets, when selecting a different sheet
Option Explicit
'Place this code in ThisWorkbook module
'Expects that all new sheets are generated by double-clicking a pivot table
Private pivotWs As Worksheet
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Set pivotWs = Sh
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Not pivotWs Is Nothing Then
If Sh.Name = pivotWs.Name Then
Application.DisplayAlerts = False
pivotWs.Delete
Set pivotWs = Nothing
Application.DisplayAlerts = True
End If
End If
End Sub

Sub that displays a line chart for a 2 entries table when a button is clicked

I am currently trying to create a sub (Excel VBA) that generates a form that displays a line chart for months and letters I want to freely select in a 2 entries table.
I want my sub to start when I click on a button that I already created (called Display Chart or Button1_Click).
Here is the code I came out with :
Sub Button1_Click()
GenerateChart.Show
End Sub
Sub GenerateChart()
On Error Resume Next
Dim MyChart As Chart
Dim DataRange As Range
If ActiveSheet.Name = "Sheet3" And Selection.Cells.Count > 0 Then
Set DataRange = Selection
Set MyChart = ActiveSheet.Shapes.AddChart.Chart
MyChart.SetSourceData Source:=DataRange
MyChart.ChartType = xlBarStacked
End If
End Sub
For some reason, this does not seem to work. I think I did something wrong regarding the button click part. Indeed, I do not understand how this event is called (Display Chart or Button1_Click) and how to code it. Therefore I cannot check if my other lines of codes are correct.
I hope someone will be able to help me out, thanks a lot !
Assign a Macro GenerateChart with the button and Select the data for which you need to create a Chart and click the button, I think you are not selected the data while you clicking the button here you used
Set DataRange = Selection

Switch pivot table filter using VBA macro (button)

I need help with some rather easy macro, but I can't do that. So all I want is to switch between filters - I have two possibilities, by example two colours - black and white, and I only want to have one of them in the moment (I want to add button, so it will work as switch). Here is the situation
I've tried did it with conditional, of course it doesn't work, but hope it will helps you to understand my idea. If one filter is enable, the other one is disabled (so the objects connected with that obviously too).
Sub Makro5()
ActiveSheet.PivotTables("PivotTable3").PivotFields("colour"). _
CurrentPage = "(All)"
If ActiveSheet.PivotTables("PivotTable3").PivotFields("colour")
.PivotItems("black").Visible = False
.PivotItems("white").Visible = True
Then ActiveSheet.PivotTables("PivotTable3").PivotFields ("colour")
.PivotItems("black").Visible = True
.PivotItems("white").Visible = False
Else: ActiveSheet.PivotTables("PivotTable3").PivotFields ("colour")
.PivotItems("black").Visible = False
.PivotItems("white").Visible = True
End Sub
Something is wrong with If, because it's on red and I get "Complie error: Syntax error" info
This is what slicers are built for.
Put your cursor inside the the pivottable data area. Then goto insert > slicer > and choose colour. You will then have a slicer which will allow you to select either or. I don't know if you can disable multiselect in current excel version so user could press ctrl and select both. But this seems a simple way.
Or you could run code such as the following and then user just types in Black or White in to field and filter is applied:
Sub Test()
Dim wb As Workbook
Dim ws As Worksheet
Dim pvt As PivotTable
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet3")
Set pvt = ws.PivotTables("PivotTable3")
Dim pvtField As PivotField
Dim item As Long
Dim item2 As Long
Set pvtField = pvt.PivotFields("Colour")
pvtField.EnableItemSelection = False
End Sub
You need to have the Then on the same line as the If. (You can use _ to tell VBA that "code continues on next line")
You also don't have your And set up correctly, and you are making both "Black" and "White" visible before you check if they are visible?
Try this:
Sub ToggleColour()
With ActiveSheet.PivotTables("PivotTable3").PivotFields("colour")
If .PivotItems("white").Visible=True Then
.CurrentPage = "black"
Else
.CurrentPage = "white"
End If
End With
End Sub

VBA macro to change filters in pivot table

I'm trying do automate a daily report and therefore I want to create two buttons which change the filters of three pivot tables. In detail the buttons shall change the day which is shown. The first filters on yesterday the second one is a reset button do clear all filters and show all days.
The "Resest"-Button is working but the "Yesterday"-Button not.
At the moment the macro looks like that:
Private Sub CommandButton2_Click()
MsgBox ActiveSheet.Range("B1")
With ActiveSheet.PivotTables("Detail_Digital").PivotFields("Tag").CurrentPage = _
ACtiveSheet.Range("B1").Value
End With
End Sub
I've also tried PivotFilters.Add _ , Type:=xlDateYesterday but that isn't working either.
Any suggestions?
Try the code below, it should work, unless your "Date" is formatted differently between the Pivot's data source and Range("B1").
Note: try to avoid using ActiveSheet, instead use referenced objects. In the case below, replace Worksheets("Sheet1") with your sheet's name.
Code
Option Explicit
Private Sub CommandButton2_Click()
Dim PvtTbl As PivotTable
Dim PvtItm As PivotItem
' set the Pivot Table
Set PvtTbl = Worksheets("Sheet1").PivotTables("Detail_Digital")
With PvtTbl
.PivotFields("Tag").ClearAllFilters ' <-- clear all filters to "Tag"
'Debug.Print Worksheets("Sheet1").Range("B1").Value
For Each PvtItm In .PivotFields("Tag").PivotItems
If PvtItm.Name = Worksheets("Sheet1").Range("B1").Value Then
PvtItm.Visible = True
Else
PvtItm.Visible = False
End If
Next PvtItm
End With
End Sub