VBA Hide Rows - Can't Lock to protect formulas

JMC57

Board Regular
Joined
Apr 24, 2012
Messages
118
I have a SS that puls data from another sheet using the following formula

=IF(OR('Site Visit ASSESSMENT'!D9={"PARTIAL COMPLIANCE","NOT COMPLIANT","NOT ASSESSED","ADDITIONAL INFO NEEDED"}),'Site Visit ASSESSMENT'!A9,"")

I also have VB Code in teh sheet as follows to hide rows. If I protect colum A and protect sheet I get an error. How can I protect the sheet and still have the following commnad work?

Private Sub CommandButton1_Click()
'Toggle rows hidden where cells in column D are blank
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
Else
Range("D3:D1000").AutoFilter Field:=1, Criteria1:="<>", VisibleDropDown:=False
End If
End Sub
Private Sub CommandButton2_Click()
Range("A3:G1000").ClearContents
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You can UNprotect the sheet with the code, then reprotect it at the end of the code..

Rich (BB code):
Private Sub CommandButton1_Click()
ActiveSheet.UnProtect "Passwordgoeshere"
 
'Toggle rows hidden where cells in column D are blank
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
Else
Range("D3:D1000").AutoFilter Field:=1, Criteria1:="<>", VisibleDropDown:=False
End If
 
ActiveSheet.Protect "Passwordgoeshere"
End Sub
 
 
Private Sub CommandButton2_Click()
ActiveSheet.UnProtect "Passwordgoeshere"
 
Range("A3:G1000").ClearContents
 
ActiveSheet.Protect "Passwordgoeshere"
End Sub
 
Upvote 0
I believe every time you run the code, you must unprotect the sheets then protect the sheets again.

Code:
Sheet1.Unprotect
Sheet1.protect
 
Upvote 0
With the protect and unprotect function it does not appear that the wrap text is not working in col a and b. These col pull data from another sheet . Is there code to auto wrap each cell?
 
Upvote 0
Well your original posted code has nothing regarding Wrap Text...

But you can use this to set the Wrap Text Property to True..
Columns("B:C").WrapText = True
 
Upvote 0
Thanks- I did not notice the issue until after I posted. I really appreciate ALL your help with this. Take care.
 
Upvote 0

Forum statistics

Threads
1,216,783
Messages
6,132,690
Members
449,748
Latest member
freestuffman

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