Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:37:15+00:00 2026-06-14T03:37:15+00:00

I have been looking for a code to lock all the cells in a

  • 0

I have been looking for a code to lock all the cells in a sheet but one and I found this code:

Worksheets("SW").Range("D2").Locked = False
Worksheets("SW").Protect UserInterfaceOnly:=True

it really worked fine until I saved it and closed/opened the file again, then any macros I had were run.

I guess it is because in that sheet I have different macros and also I have the macro that runs when a cell is changed:

Private Sub Worksheet_Change(ByVal Target As Range)

Do you have any idea how to make it work?

One more thing, this workbook it will be shared, so I don’t know that will affect the macros.

sorry maybe I was too ambiguous.

Yes I want to prevent others to change de value of the cells.

I want that just one cell could be changed so all the others are changing with the macros.

Thanks again for all your help

PS: yes Ahmad Al-Mutawa, I want to be impossible to chang the sheet even after the project being saved, closed and opened.

If you need more info just tell me I’ll try to be more specific.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:37:16+00:00Added an answer on June 14, 2026 at 3:37 am

    Does your file have any macros doing other operations than this lock unlock code you are trying to achieve?

    If so I suggest you having a code in vba. Otherwise you can simply lock the sheets to prevent users from changing somethings or anytime at all without a code.

    do you think this could be better for you than a [code][1]?

    [ http://office.microsoft.com/en-us/excel-help/lock-or-unlock-specific-areas-of-a-protected-worksheet-HA010096837.aspx ][1]

    Out of curiosity: BY ANY CHANCE are you having an issue not knowing where and how to trigger this code piece?

    Edited code:-
    Your comment is not clear, nonethless I believe you want to use a macro.
    Assuming you want to protect/lock or unprotect/unlock Sheet1, please try the following. :-

    Add this code in Workbook open event in thisworkbook:-

    Private Sub Workbook_Open()
      Dim shtSheet As Worksheet
      Dim strPassword As String
    
        strPassword = "stack"
        Set shtSheet = Worksheets("Sheet1")
        shtSheet.Protect Password:=strPassword, UserInterfaceOnly:=True
    End Sub
    

    Next add the following in your module. And call it after you finish running your macro.

     Sub ProtectSheet()
      Dim shtSheet As Worksheet
      Dim strPassword As String
    
         strPassword = "stack"
         Set shtSheet = Worksheets("Sheet1")
         shtSheet.Protect strPassword
     End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at some assembly code and have found that this comes
I have been looking over this code for the past hour, I cant see
I have been looking at this piece of code for the last 3 hours
I have been looking at this code and I'm confused about the rep cmpsb
I have been looking online and in the android opencv source code, but I
I have been looking at this code and I am having trouble understanding the
I have been looking through code and forums for hours. Does any one know
I have been looking at the code below which I found here: http://tehc0dez.blogspot.co.uk/2010/04/nice-curves-catmullrom-spline-in-c.html ///
I have been looking through code for the last 3 days, and the original
I have been looking through some code on an open source project recently and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.