Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set the hidden property of the range class run time error '1003'

Tags:

excel

vba

I have code in this module:

Sub HideSalTable()

User = Worksheets("log").Range("R1").Value
If User = ThisWorkbook.Worksheets("SSSSSS").Range("za1").Value Then
Columns("S:AA").EntireColumn.Hidden = True

ElseIf User = ThisWorkbook.Worksheets("SSSSSS").Range("za3").Value Then
Columns("S:AA").EntireColumn.Hidden = False

ElseIf User = ThisWorkbook.Worksheets("SSSSSS").Range("za4").Value Then
Columns("S:AA").EntireColumn.Hidden = False

End If

End Sub

I have a button to redirect me to ThisWorkbook.Worksheets("SSSSSS") with this code:

Private Sub Change_SSSSSS_Button_Click()

 Dim pass1 As String
  Dim pass2 As String
  pass1 = ThisWorkbook.Worksheets("SSSSSS").Range("za3").Value
   pass2 = ThisWorkbook.Worksheets("SSSSSS").Range("za4").Value
  Dim Inp
    Dim lTries As Long



    lTries = 1
    Do
        Inp = InputBoxDK("enter password", "Zmhnk")
        If Inp = "" Or Inp = vbCancel Then Exit Sub          '* Cancel button pressed or nothing entered
        If Inp = (pass1) Or Inp = (pass2) Then
            Exit Do
        End If
        lTries = lTries + 1
        If lTries > 4 Then
            MsgBox "Error", vbInformation, "Zmhnk"
            Exit Sub
        Else
            If MsgBox("try again", vbYesNo, "error_Zmhnk") = vbNo Then Exit Sub
        End If
    Loop

 Application.ScreenUpdating = False

 Sheets("SSSSSS").Visible = True
 Sheets("SSSSSS").Activate

 Application.ScreenUpdating = True

End Sub

The problem is when the user presses the button with the 2nd code I face an error and I don't know why.

The error:

Unable to set the hidden property of the range class run time error '1003'
like image 980
Zaid Kalthoum Avatar asked Sep 05 '12 03:09

Zaid Kalthoum


1 Answers

Two things

1) You have not fully qualified your range. I understand that you are getting redirected but this is much safer.

Columns("S:AA").EntireColumn.Hidden = True

Change it to

ThisWorkbook.Sheets("SSSSSS").Columns("S:AA").EntireColumn.Hidden = True

2) I believe your worksheet is protected. You have to unprotect it. You can do that as follows

ThisWorkbook.Sheets("SSSSSS").Unprotect "myPassword"
like image 166
Siddharth Rout Avatar answered Oct 20 '22 09:10

Siddharth Rout