I have an excel file with a macro that runs on VBA script. The macro works great on windows office 16, but will not work on a Mac office 16. There must be problems in the commands I am using that are not compatible in a Mac.
Could any of you read through my code below and see if you can recommend which commands/functions are causing the problem? And recommend a replacement that will perform the same across OS platforms (windows/mac)? Thanks!
Object:
Could any of you read through my code below and see if you can recommend which commands/functions are causing the problem? And recommend a replacement that will perform the same across OS platforms (windows/mac)? Thanks!
Object:
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'Run the filter columns macro when the pivot table or slicer is changed
Dim pvt As PivotTable
'Unhide all columns first
Call m_Filter.Unhide_Columns("rngApplianceCol", "Appliances")
Call m_Filter.Unhide_Rows("rngApplianceRow", "Appliances")
For Each pvt In Target.Parent.PivotTables
Call m_Filter.Filter_Columns("rngApplianceCol", "Appliances", "Appliances", "Appliance Selection", "Appliance")
Call m_Filter.Filter_Rows_Appliance("rngApplianceRow", "Appliances", "Appliances", "Appliance Selection", "Appliance")
Next pvt
End Sub
[B]Module:[/B]
Sub Unhide_Columns(sHeaderRange As String, _
sReportSheet As String)
'Unhide all columns
Worksheets(sReportSheet).Range(sHeaderRange).EntireColumn.Hidden = False
End Sub
Sub Unhide_Rows(sHeaderRange As String, _
sReportSheet As String)
'Unhide all rows
Worksheets(sReportSheet).Range(sHeaderRange).EntireRow.Hidden = False
End Sub
Sub Filter_Columns(sHeaderRange As String, _
sReportSheet As String, _
sPivotSheet As String, _
sPivotName As String, _
sPivotField As String _
)
Dim c As Range
Dim rCol As Range
Dim pi As PivotItem
'Loop through each cell in the header range and compare to the selected filter item(s).
'Hide columns that are not selected/filtered out.
For Each c In Worksheets(sReportSheet).Range(sHeaderRange).Cells
'Check if the pivotitem exists
With Worksheets(sPivotSheet).PivotTables(sPivotName).PivotFields(sPivotField)
On Error Resume Next
Set pi = .PivotItems(c.Value)
On Error GoTo 0
End With
'If the pivotitem exists then check if it is visible (filtered)
If Not pi Is Nothing Then
If pi.Visible = False Then
'Add excluded items to the range to be hidden
If rCol Is Nothing Then
Set rCol = c
Else
Set rCol = Union(rCol, c)
End If
End If
End If
'Reset the pivotitem
Set pi = Nothing
Next c
'Hide the columns of the range of excluded pivot items
If Not rCol Is Nothing Then
rCol.EntireColumn.Hidden = True
End If
End Sub
Sub Filter_Rows_Appliance(sHeaderRange As String, _
sReportSheet As String, _
sPivotSheet As String, _
sPivotName As String, _
sPivotField As String _
)
Dim c As Range
Dim rCol As Range
Dim pi As PivotItem
'Loop through each cell in the header range and compare to the selected filter item(s).
'Hide rows that are not selected/filtered out.
For Each c In Worksheets(sReportSheet).Range(sHeaderRange).Cells
'Check if the pivotitem exists
With Worksheets(sPivotSheet).PivotTables(sPivotName).PivotFields(sPivotField)
On Error Resume Next
Set pi = .PivotItems(c.Value)
On Error GoTo 0
End With
'If the pivotitem exists then check if it is visible (filtered)
If Not pi Is Nothing Then
If pi.Visible = False Then
'Add excluded items to the range to be hidden
If rCol Is Nothing Then
Set rCol = c
Else
Set rCol = Union(rCol, c)
End If
End If
End If
'Reset the pivotitem
Set pi = Nothing
Next c
'Hide the rows of the range of excluded pivot items
If Not rCol Is Nothing Then
rCol.EntireRow.Hidden = True
End If
End Sub
Last edited by a moderator: