Hiding/unhiding rows problems

keelybin

New Member
Joined
Jun 30, 2014
Messages
37
Hi folks,

I've had this code working but for some reason it keeps stopping working with a 1004 error (unable to set the hidden property of the range class) and I cant figure out why - do you have any idea?

There is other code in there but essentially I'm trying to hide/unhide rows, in this example row 24, initially and if any drop down option is selected (cell c23) then it reappears.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Row_int As Integer
Dim Check_Rng As Range
Dim N_int As Integer
Dim Hide_row_int As Integer


Application.ScreenUpdating = False

[B]If Target.Address = "$C$23" Then[/B][B]    Rows("24").Hidden = True[/B]
[B]    If Target.Value <> "" Then[/B]
[B]        Rows("24").Hidden = False[/B]
[B]    End If[/B]
[B]End If

[/B]Application.ScreenUpdating = True
end sub

The worksheet is password protected btw
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Row_int As Integer
Dim Check_Rng As Range
Dim N_int As Integer
Dim Hide_row_int As Integer


Application.ScreenUpdating = False
Me.Unprotect
If Target.Address = "$C$23" Then Rows("24").Hidden = True
    If Target.Value <> "" Then
        Rows("24").Hidden = False
    End If
End If
Me.Protect
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hmm nope its giving me an error now "Compile error: End if without block if".

I cant understand how it sometimes works and sometimes doesnt. Generally the sheet is protected (but not written into the macro) as I need some cells locked, but we're addressing the unlocked cells here with the code :(
 
Upvote 0
There was an extra End If in the code that you posted. Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Row_int As Integer
Dim Check_Rng As Range
Dim N_int As Integer
Dim Hide_row_int As Integer


Application.ScreenUpdating = False
Me.Unprotect
If Target.Address = "$C$23" Then Rows("24").Hidden = True
If Target.Value <> "" Then
    Rows("24").Hidden = False
End If
Me.Protect
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you. Your code works when I try my sheet in a brand new document so I can only assume there must be additional code in my original workbook stopping this from working. Back to the drawing board! lol
 
Upvote 0

Forum statistics

Threads
1,203,521
Messages
6,055,891
Members
444,831
Latest member
iceonmn

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