+ Reply to Thread
Results 1 to 9 of 9

Run-time error when hiding columns in protected workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Run-time error when hiding columns in protected workbook

    Hello,

    I have a listbox whose selections hide or unhide particular columns. I receive a run-time error 1004 only when I attempt to use this after just having activated the protected workbook. If I unprotect the workbook and reprotect it, the listbox functions properly from then on. I only have trouble if I haven't yet unprotected it.

    I have unlocked all of the cells in the columns I am hiding as I thought this might be the issue. Can anyone offer me some suggestions? Here is the code I'm using with the error messages listed below:

    Public Sub Hide_Graph()
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        If [Display_Selected] = 2 Then
            Worksheets("Exhibit Summary").Range("G:Y").EntireColumn.Hidden = True
            Worksheets("Exhibit Summary").Range("AA:AJ").EntireColumn.Hidden = False
        ElseIf [Display_Selected] = 1 Then
            Worksheets("Exhibit Summary").Range("AA:AJ").EntireColumn.Hidden = True
            Worksheets("Exhibit Summary").Range("G:Y").EntireColumn.Hidden = False
        Else
            Worksheets("Exhibit Summary").Range("G:AJ").EntireColumn.Hidden = False
        End If
        ActiveSheet.Range("A1").Select
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub
    “400” Error message

    “Run-time error ‘1004’:
    Application-defined or object-defined error”

    Thanks ahead of time!

    Joe
    Last edited by JoeSkittles; 04-01-2013 at 08:38 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run-time error when hiding columns in protected workbook

    Joe

    Perhaps, have code to unprotect, followed by the hidey columns and then have code to reprotect.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Run-time error when hiding columns in protected workbook

    Hi and welcome to the forum.

    Pls take few minutes to read forum rules, because:

    Your Post does not comply with number 3 rule of our forum
    . Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Select your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Run-time error when hiding columns in protected workbook

    Norie, thanks for your reply. This seems to work, but I'm prompted for the unprotect password when I select a new listbox option. Is there a way that I can unprotect (and then reprotect later) the sheet without being prompted for this password. I do want the sheet to be password protected in general, but I just don't want it to be required for this listbox to be selected.

    Fotis, I'm sorry for failing to use tags. I attempted to resolve this. Please let me know if I did this incorrectly or if there are other changes I need to make. Thank you for helping out a rookie.

    Joe

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run-time error when hiding columns in protected workbook

    Joe

    Have you tried unlocking the listbox before protecting?

    You might have to unprotect the cells associated with it to.

    I think seeing a workbook would be helpful.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  6. #6
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Run-time error when hiding columns in protected workbook

    Norie,

    I tried using unlocking the listbox, but that did not make a difference. I'm wondering if locking is not the issue, since I'm receiving the 400 error for application or object-definded...

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run-time error when hiding columns in protected workbook

    Which line of code is the error on?

  8. #8
    Registered User
    Join Date
    03-30-2013
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: Run-time error when hiding columns in protected workbook

    If I am selecting option number 2, then it would be on the

    Worksheets("Exhibit Summary").Range("G:Y").EntireColumn.Hidden = True
    line (which is the fourth from the top if you look at the original code)

    Thanks so much!

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run-time error when hiding columns in protected workbook

    Joe

    I really think it would help if you uploaded a workbook.

    Otherwise all we can do is make guesses and suggestions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1