Unable to Unhide Columns

reyrey

New Member
Joined
Jun 30, 2011
Messages
49
Hello all!

Im getting the following error below

"Unable to set the Hidden property of the Range class"

Any idea why im getting error?

Code:
Sub UnlockSheet()

Dim password As Variant
              password = Application.InputBox("Enter Password", "Password Protected")
    Select Case password
                  Case Is = False
                      
                  Case Is = "MyPassword"
                                                     
                  Case Else
                      MsgBox "Incorrect Password"
    End Select

Columns.EntireColumn.Hidden = False

End Sub
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
I suspect it's because, you haven't unlocked the sheet.
 

reyrey

New Member
Joined
Jun 30, 2011
Messages
49
But I thought when running the code it unlocks the code? Shouldn't it
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
To unlock the sheet try
Code:
Sub UnlockSheet()
   
   Dim PassWrd As Variant
   
   PassWrd = Application.InputBox("Enter Password", "Password Protected")
   If PassWrd = "MyPassword" Then
      Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Unprotect PassWrd
      Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Columns.EntireColumn.Hidden = False
   Else
      MsgBox "Incorrect Password"
   End If
   
End Sub
Change sheet name in red to suit
 

Watch MrExcel Video

Forum statistics

Threads
1,122,216
Messages
5,594,886
Members
413,947
Latest member
gizmolucy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top