Hi everyone,
I am using the following User Defined Function to count the number of indents in a cell.
However, I am having a problem with the function returning #VALUE after I run the macro code below which is used to hide and unhide certain rows and columns on the worksheet. Only the functions in the rows that have been hidden or unhidden are affected.
I put a debug into the first loop of this code to print the value in one of the cells containing the function in a hidden row, and it errored out on the first iteration of the loop even though row 1 would not be hidden. I don't understand the correlation between my macro and the udf. If I manually hide and unhide rows it has no effect.
Any help is much appreciated!
Thanks,
V
I am using the following User Defined Function to count the number of indents in a cell.
Code:
Public Function IndentCount(rCell As Range) As Long
IndentCount = rCell.IndentLevel
End Function
However, I am having a problem with the function returning #VALUE after I run the macro code below which is used to hide and unhide certain rows and columns on the worksheet. Only the functions in the rows that have been hidden or unhidden are affected.
Code:
Sub toggleAdminView()
If Application.UserName = "Vincent Afnan-Murray" Then
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="Lotus491"
Selection.SpecialCells(xlCellTypeLastCell).Select
lastRow = Selection.Row
lastCol = Selection.Column
Dim adminView As Boolean
Debug.Print "Before rows are hidden " & Range("AI3").Value
Dim r As Integer
For r = 1 To lastRow
If Cells(r, 1).Value = "h" Or Cells(r, 1).Value = "sv" Then
If Cells(r, 1).EntireRow.Hidden = False Then
Cells(r, 1).EntireRow.Hidden = True
Else
Cells(r, 1).EntireRow.Hidden = False
End If
End If
Next
Dim c As Integer
For c = 1 To lastCol
If Cells(1, c).Value = "h" Or Cells(1, c).Value = "sv" Then
If Cells(1, c).EntireColumn.Hidden = False Then
Cells(1, c).EntireColumn.Hidden = True
Else
Cells(1, c).EntireColumn.Hidden = False
adminView = True
End If
End If
Next
Application.ScreenUpdating = True
Debug.Print "Before sheet is protected " & Range("AI3").Value
If adminView = True Then
Range("A1").Select
Else
With ActiveSheet
.Protect Password:="Lotus491", UserInterfaceOnly:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True, AllowFiltering:=True
.EnableOutlining = True
End With
End If
Else
MsgBox "You are not authorised to access Admin View"
End If
End Sub
I put a debug into the first loop of this code to print the value in one of the cells containing the function in a hidden row, and it errored out on the first iteration of the loop even though row 1 would not be hidden. I don't understand the correlation between my macro and the udf. If I manually hide and unhide rows it has no effect.
Any help is much appreciated!
Thanks,
V
Last edited: