

Note: Since now the workbook has a VBA macro in it, you need to save it in the macro-enabled format (.XLSM).


To use this code, you need to add this to a module in the Visual Basic Editor in Excel, and then run this code from there.īelow are the steps to add this VBA code to unhide rows to a module in VB Editor: In case you want to unhide rows in all the worksheets at one go, you can do that as well.īelow is the VBA code that will go through each worksheet in the active workbook and then unhide all the rows in that worksheet: Sub UnhideSpecificROws() Unhide Rows in All the Worksheets in Excel Using VBA The above uses the FOR NEXT loop to go through each row in the first 20 rows and then makes the hidden property FALSE, which is equivalent to making all rows visible. In case you want to unhide sheets in a specific range only (let’s say unhide all hidden rows in the first 20 rows only), you can use the below code: Sub UnhideSpecificROws() Unhide Rows in a Worksheet in Excel Using VBAīelow is the VBA code that will instantly unhide all the rows in the entire worksheet Sub UnhideAllRows() Adding the Macro to the Quick Access Toolbar.

Unhide Rows in All the Worksheets in Excel Using VBA.Unhide Rows in a Worksheet in Excel Using VBA.If the user is incorrect, send them back to a different sheet and display a message. Yes, instead of performing your checks on workbook open, you could check the username when the sheet is activated. Lastly, none of this will work if someone disables their macros! Comments It's a good idea to also create a blank sheet to open the workbook onto, to stop details from being read whilst the message box is active. Just want to grab the code and get it working? Here's the complete code: Private Sub Workbook_Open() Dim user As String Dim users( 5) As String users( 0) = "SomeUser" users( 1) = "SomeUser" users( 2) = "SomeUser" users( 3) = "SomeUser" users( 4) = "SomeUser" user = Application.UserName Dim access As Boolean Dim i As Integer access = False For i = 0 To 4 If users(i) = user Then access = True Exit For End If Next If access = False Then MsgBox ( "Sorry, the user """ & "Liam" & """ does not have the correct access rights to view this workbook") ActiveWorkbook.Close End If End Sub NOTEĭont forget to change the number of loops if you change the number of users or some will get missed or an error will occur!
