Hello,
I created the code (below) on a PC and the file works great! Our company has started issuing macs to some users and one of the people who got one just ran one of my workbooks and got this error:
"Compile error:
Expected Function or variable"
The error occurs at the first ".ClearContents". Since it is getting hung up there, I can only assume it might get hung up on the others.
ANY HELP WOULD BE APPRECIATED!
Here is the code:
Option Explicit
Private Sub Worksheet_Activate()
'This code unprotects the sheet using the correct password
ActiveSheet.Unprotect Password:=Worksheets("Backend Data").Range("BC2").Value
'write "Generating Budget... please be patient." at the bottom of the excel screen while code runs.
Application.StatusBar = "Generating Budget... please be patient."
'???Could this be code that hides ZERO values???
ActiveWindow.DisplayZeros = True
'While code is running, don't refresh the screen
Application.ScreenUpdating = False
'Defining PvtTable as a Pivot Table
Dim PvtTable As PivotTable
'Defining variable as a range. preceeding variable with "rng" as a mental reminder when looking at it below that it is a range object
Dim rngCellBeingChecked As Range
'For each Pivot Table in the specified worksheet,
For Each PvtTable In Worksheets("#3 Pivot Table for Budget").PivotTables
'Refresh the table
Worksheets("#3 Pivot Table for Budget").Unprotect Password:=Worksheets("Backend Data").Range("BC2").Value
PvtTable.RefreshTable
Worksheets("#3 Pivot Table for Budget").Protect Password:=Worksheets("Backend Data").Range("BC2").Value
Next PvtTable
'**********HIDE/SHOW ROWS************
'Repeat this process for each rngCellBeingChecked in the following range
'PRODUCTION, FOOD&ENT, BRANDING, COMMS, and REVENUE - defined by the ranges
For Each rngCellBeingChecked In Range("F5:F59,F62:F116,F119:F153,F156:F210,F213:F224")
'If the value it is checking = "1", then
If rngCellBeingChecked.Value = "1" Then
'make the row visible
rngCellBeingChecked.EntireRow.Hidden = False
Else
'else make the row invisible and delete the dollar value for that line item (so it isn't factored into budget if removed from the budget
rngCellBeingChecked.EntireRow.Hidden = True And rngCellBeingChecked.Offset(0, -1).ClearContents = True And rngCellBeingChecked.Offset(0, 1).ClearContents = True And rngCellBeingChecked.Offset(0, 2).ClearContents = True And rngCellBeingChecked.Offset(0, 3).ClearContents = True And rngCellBeingChecked.Offset(0, 4).ClearContents = True
End If
Next
'SUMMARY - doing this separate because I do not want any cell values cleared like the code above is doing
For Each rngCellBeingChecked In Range("F237:F283")
'If the value it is checking = "1", then
If rngCellBeingChecked.Value = "1" Then
'make the row visible
rngCellBeingChecked.EntireRow.Hidden = False
Else
'else make the row invisible
rngCellBeingChecked.EntireRow.Hidden = True
End If
Next
'Refreshes the page after all code runs
Application.ScreenUpdating = True
'After all the code is run, the next line locks the sheet again
ActiveSheet.Protect Password:=Worksheets("Backend Data").Range("BC2").Value ', DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
'Remove the Status Bar once the code has finished
Application.StatusBar = False
End Sub
Bookmarks