VBA not working when sheet locked

Russk68

Well-known Member
Joined
May 1, 2006
Messages
586
Office Version
  1. 365
Platform
  1. MacOS
Hi All,

The (Incomplete) code below hides rows based on a value of GF3 and works great until I password protect the sheet. How can I get this to work when the sheet is PW protected? I assume the code would have to unlock/lock the sheet each time the macro is ran?


If Target.Count = 1 Then
If Range("GF3").Value < "3" Then
Rows("13:52").EntireRow.Hidden = True
ElseIf Range("GF3").Value = "6" Then
Rows("13:52").EntireRow.Hidden = False
End If
End If
End If
If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x24
If Target.Count = 1 Then
If Range("GF3").Value < "4" Then
Rows("21:52").EntireRow.Hidden = True
End If
End If
End If
If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x48
If Target.Count = 1 Then
If Range("GF3").Value < "5" Then
Rows("37:52").EntireRow.Hidden = True
End If End If
End If
If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x60
If Target.Count = 1 Then
If Range("GF3").Value < "6" Then
Rows("45:52").EntireRow.Hidden = True
End If
End If
End If

Thank you!
Russ
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this. Change "abc" by the desired password


Code:
[COLOR=#0000ff]activesheet.unprotect "abc"[/COLOR]

[COLOR=#333333]If Target.Count = 1 Then[/COLOR]
[COLOR=#333333]If Range("GF3").Value < "3" Then[/COLOR]
[COLOR=#333333]Rows("13:52").EntireRow.Hidden = True[/COLOR]
[COLOR=#333333]ElseIf Range("GF3").Value = "6" Then[/COLOR]
[COLOR=#333333]Rows("13:52").EntireRow.Hidden = False[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x24[/COLOR]
[COLOR=#333333]If Target.Count = 1 Then[/COLOR]
[COLOR=#333333]If Range("GF3").Value < "4" Then[/COLOR]
[COLOR=#333333]Rows("21:52").EntireRow.Hidden = True[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x48[/COLOR]
[COLOR=#333333]If Target.Count = 1 Then[/COLOR]
[COLOR=#333333]If Range("GF3").Value < "5" Then[/COLOR]
[COLOR=#333333]Rows("37:52").EntireRow.Hidden = True[/COLOR]
[COLOR=#333333]End If End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]If Not Intersect(Target, Range("F1")) Is Nothing Then 'Distro#1x60[/COLOR]
[COLOR=#333333]If Target.Count = 1 Then[/COLOR]
[COLOR=#333333]If Range("GF3").Value < "6" Then[/COLOR]
[COLOR=#333333]Rows("45:52").EntireRow.Hidden = True[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End If

[/COLOR][COLOR=#0000ff]activesheet.protect "abc"[/COLOR]
 
Upvote 0
Hey Dante
This is actually your original code.
Thanks for your help again!
Works great!
 
Upvote 0
It's pleasure and thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,211,685
Messages
6,103,287
Members
447,853
Latest member
olddutch7

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