+ Reply to Thread
Results 1 to 5 of 5

Error 400 when sheet is protected

Hybrid View

Master Foo Error 400 when sheet is... 07-03-2013, 03:00 PM
shg Re: Error 400 when sheet is... 07-03-2013, 03:39 PM
Master Foo Re: Error 400 when sheet is... 07-03-2013, 04:06 PM
jolivanes Re: Error 400 when sheet is... 07-03-2013, 03:47 PM
Master Foo Re: Error 400 when sheet is... 07-03-2013, 04:07 PM
  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2013
    Posts
    19

    Error 400 when sheet is protected

    When using the code below it works perfectly with the sheet Not protected but after protecting the sheet it gives (error 400) and opens the VB Editor after pressing the button but it still puts the correct values in the cells. The cells that are used are not locked but other adjacent cells are. I can't figure out why it is giving that error or how to correct it so that it does not give the error with the sheet protected.

    -----------

    Sub Dates()

    Dim i As Integer
    Range("A5").Select
    For i = 1 To 7
    ActiveCell.FormulaR1C1 = "=TODAY() - WEEKDAY(TODAY()*0.2)+" & i
    ActiveCell.Offset(1, 0).Select
    Next i
    Range("A5:A11").NumberFormat = "DDDD ~ m/d/yy"

    End Sub

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Error 400 when sheet is protected

    You code will try to select A12, which won't work if it's locked and the protection disallows selection of locked cell. But there's no need to select:

    Sub Dates()
        Dim i           As Long
        
    
        For i = 1 To 7
            Range("A5")(i).FormulaR1C1 = "=TODAY() - WEEKDAY(TODAY()*0.2) + " & i
        Next i
    
        Range("A5:A11").NumberFormat = "DDDD ~ m/d/yy"
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-14-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2013
    Posts
    19

    Re: Error 400 when sheet is protected

    shg - that still gives error 400 when the sheet is protected. I had previously unlocked cell A12 thinking the same thing but still got the error when the sheet was protected.
    Last edited by Master Foo; 07-03-2013 at 04:11 PM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,703

    Re: Error 400 when sheet is protected

    Does this work?


    Sub Dates()
        Dim i As Integer
        ActiveSheet.Unprotect ("Password")    '<----- Change to actual password
        Range("A5").Select
        For i = 1 To 7
            ActiveCell.FormulaR1C1 = "=TODAY() - WEEKDAY(TODAY()*0.2)+" & i
            ActiveCell.Offset(1, 0).Select
        Next i
        Range("A5:A11").NumberFormat = "DDDD ~ m/d/yy"
        ActiveSheet.Protect Password:="Password", _
                            UserInterFaceOnly:=True
    End Sub
    Re: You code will try to select A12 (shg)
    Did not notice that.

  5. #5
    Registered User
    Join Date
    05-14-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 2013
    Posts
    19

    Re: Error 400 when sheet is protected

    jolivanes - That works perfectly. Thanks Very much.

+ 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