Share via

Help to hide Rows

Anonymous
2024-08-08T09:54:01+00:00

Hi,

I'd like to know if there is a (possibly VBA) solution to hiding row 18-20 based on cell M10 is more than 0.

Rows <- imgur.. Sorry, i can't insert a screenshot of the sheet.

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2024-08-08T13:31:30+00:00

    Sub Worksheet_Change(ByVal Target As Range)

       If Target.Address(0,0) = "M10" Then

                   Me.Unprotect Password:="TL1234"

                   Rows("18:20").Hidden = Target > 0

                   MeProtect Password:="TL1234"

       End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-08-08T13:23:28+00:00

    Nope, just a cell for the user to write in.

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2024-08-08T13:07:15+00:00

    Does M10 contain a formula?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-08-08T12:01:44+00:00

    Thanks, it doesn't quite cut it unfortunately...

    Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$M$10" Then
    If Target.Value > 0 Then
    If ActiveSheet.ProtectContents Then
    ActiveSheet.Unprotect Password:="TL1234"
    Rows("18:20").EntireRow.Hidden = False
    ActiveSheet.Protect Password:="TL1234"
    End If
    Else
    If ActiveSheet.ProtectContents Then
    ActiveSheet.Unprotect Password:="TL1234"
    Rows("18:20").EntireRow.Hidden = True
    ActiveSheet.Protect Password:="TL1234"
    End If
    End If
    End If
    End Sub

    I tried some AI, because i want the sheet to be partially locked for users.

    Can you see what might be wrong with this.. It doesn't seem to work?

    Was this answer helpful?

    0 comments No comments
  5. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2024-08-08T10:14:42+00:00

    Sub Test()

    Rows("18:20").Hidden = Range("M10") > 0
    End Sub

    Was this answer helpful?

    0 comments No comments