I have a Array of users of a workbook that I want if the username is not in my Array then columns (O:P) must be hidden.
I got a Type Mismatch error and have no idea what the problem is. Thanks
Here is my code:
userlist = Array("user1", "user2", "user3", "user4")
If Application.UserName <> userlist Then
Worksheets("Master").Range("O:P").EntireColumn.Hidden = True
End If
The problem is the code tries to test whether a string is equal to an array of strings. Strings and arrays are different data types, and that produces the error.
If you want to test whether a string is equal to any of the strings in an array, this is a common method:
Filterwill filter the array to items that matchUserName.If the filtered array has one matching item,
UBoundwill equal 0. If the filtered array has no matching items,UBoundwill equal -1.