Run-time error 1004 while conditionally hiding rows as a result ofworksheet protection

R

ran58

Hello,

I have used the code below, which is tied to a multi-drop-down-list in
order to unhide/hide rows (unhiding rows = yes = 1, hiding rows = no =
2.

The macro works fine, unless the worksheet is being protected. I then
get a runtime-error 1004, saying the hidden property of the range
object cannot be determined (Code-Line 8). Is there any work-around
about this available? Many many thanks!


Sub HideRows()

Dim Rng As Range

Set Rng = Sheets("Ziel1").Range("K6")

If Rng.Value = 1 Then

Rows("7:19").EntireRow.Hidden = False

Range("K6").Select

ElseIf Rng.Value = 2 Then

Rows("7:19").EntireRow.Hidden = True

End If

End Sub
 
L

Luke M

When you protect the sheet, you need to have the option of "Format rows"
enabled, or you can't hide/unhide rows.

VBA for this is:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingRows:=True
 
R

ran58

When you protect the sheet, you need to have the option of "Format rows"
enabled, or you can't hide/unhide rows.

VBA for this is:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingRows:=True
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*

Hi Luke, many thanks for your help. Where do I place this code further
to the code that I wrote down? Sorry, but I am not a VBA-Crack at
all.... Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top