ActiveSheet.Unprotect on a Mac

mwollert

New Member
Joined
Jul 13, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
I am finding Excel VBA is very unstable on a Mac. Among other things, the command ActiveSheet.Unprotect does not appear to be working.

If I run a macro that attempts to hide a column and even though I have 'ActiveSheet.Unprotect', I still get an error "Alert - The cell or chart you are trying to change is on a protected sheet. To make a change, unprotect the sheet. You might me requested to enter a password."

When I click on "OK" the code continues correctly.

Does anyone have any suggestions to stop the alert message?

THe code is below.
VBA Code:
Sub Hide_Memo_Col()

    Dim HeaderRng As Range
    Dim c As Range
 
    ActiveSheet.Unprotect
    OptimizeCode_Begin

 
    Set HeaderRng = ActiveSheet.Range("AllBudgetHeaders")
 
    For Each c In HeaderRng
        If c Like "Ck Memo or Savings Code" Then
            c.EntireColumn.Hidden = Not c.EntireColumn.Hidden
            Exit For
        End If
    Next c
 
    OptimizeCode_End
    ActiveSheet.Protect
 
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Line 6 of your above code shows ActiveSheet.Protect, not ActiveSheet.Unprotect

VBA Code:
    ActiveSheet.Protect
    OptimizeCode_Begin
 
Upvote 0
Line 6 of your above code shows ActiveSheet.Protect, not ActiveSheet.Unprotect

VBA Code:
    ActiveSheet.Protect
    OptimizeCode_Begin

Sorry, I did edit the post right away but you must have seen it when before I edit the post.

I do have ActiveSheet.Unprotect in the code

VBA Code:
ub Hide_Memo_Col()

    Dim HeaderRng As Range
    Dim c As Range
    
    ActiveSheet.Unprotect
    OptimizeCode_Begin

    
    Set HeaderRng = ActiveSheet.Range("AllBudgetHeaders")
    
    For Each c In HeaderRng
        If c Like "Ck Memo or Savings Code" Then
            c.EntireColumn.Hidden = Not c.EntireColumn.Hidden
            Exit For
        End If
    Next c
    
    OptimizeCode_End
    ActiveSheet.Protect
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top