I am trying to hide some columns and prevent the user to have any access to them; while they can edit other parts of the sheet.
What I am seeking is something like:
ActiveWorkbook.Sheets("Name").Visible = xlSheetVeryHidden
So user cannot see them. I am aware that one option is adding another sheet and move those columns to there and hide that one sheet; but as I am working on a relatively large data-set and it has a standard format within the company, I prefer not to do so.
I already tried locking the columns and protecting the sheets and checking all the boxes except the ones for selecting locked cells, inserting and deleting both rows and columns (code below).
Function VeryHideColumn(myColumn As Range) myColumn.Locked = True myColumn.FormulaHidden = True myColumn.Hidden = True 'myColumn.Hidden = xlVeryHidden 'I already tried this ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _ False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _ AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowSorting:= _ True, AllowFiltering:=True, AllowUsingPivotTables:=True ActiveSheet.EnableSelection = xlUnlockedCells End Function
This is the problem: users still can select a range containing these hidden and locked columns and unhide them. Is there any method or trick like
VeryHidden for sheets available for ranges?
If the users don’t need to format the columns and rows, then there’s a work around for this:
AllowFormattingRows were false (which is default if not stated), then user would not be able to hide or unhide them.
Function below “very hides” only the columns based on above idea;
Function VeryHideColumn(myColumn As Range) 'By M-M, April 2017 myColumn.Locked = True myColumn.Hidden = xlVeryHidden myColumn.FormulaHidden = True ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _ False, AllowFormattingCells:=True, AllowFormattingRows:=True, _ AllowInsertingHyperlinks:=True, AllowSorting:=True, AllowFiltering:=True _ , AllowUsingPivotTables:=True End Function
If you want to very hide the rows, then set the
AllowFormattingRows to false.