• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 941
  • Last Modified:

Prevent user to unhide rows

I got a code and works well on hide/unhide info base on column G values:

Sub HideData()
 Dim cel As Range
 
 For Each cel In Columns("G")
  If LCase(Trim(cel.Text)) = "NIL" Then

   Rows(cel.Row).EntireRow.Hidden = True

  End If
 Next cel
   
End Sub



Sub SHOWData()
 Dim cel As Range
 For Each cel In Columns("G")
  If LCase(Trim(cel.Text)) = "NIL" Then
   Rows(cel.Row).EntireRow.Hidden = False

  End If
 Next cel
End Sub


However, I want to protect and prevent the users to unhide the row information when it is hidden. Any method?

Help....thanks!
0
hkgal
Asked:
hkgal
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
BardobraveCommented:
Have you tried blocking the worksheet?
0
 
hkgalAuthor Commented:
I just want to prevent then unhide and with other function normal, also users can still unhide other rows except that programmed ones...
0
 
BardobraveCommented:
Well... and what about erasing those rows from the sheet? If users shouldn't be able to see them in any manner what's the point of having them there?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Martin LissOlder than dirtCommented:
You could put the rows in a different sheet and then hide/protect the sheet.
0
 
hkgalAuthor Commented:
So no ways to hide the rows at the same time set things to prevent unhide?? in same place n worksheet?
0
 
Martin LissOlder than dirtCommented:
I don't believe there is.
0
 
BardobraveCommented:
I don't know any way to directly block a cell or a row/column from show/hide.

Maybe by rendering them readonly? Have you tried it?
0
 
aikimarkCommented:
You can add code to either the worksheet's SelectionChange() event or the workbook's SheetSelectionChange() event.  If the selection is one or more rows or all the cells, then you can change the selection programmatically.  The row(s) must be selected before they can be unhidden.

You should also make the font and interior color of the hidden cells such that it will be very difficult to read even if the row is unhidden.

Worksheet-level example:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Columns.Count = Target.Worksheet.Columns.Count Then
        Target.Cells(1, 1).Select
    End If
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now