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 1018783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:54:37+00:00 2026-05-16T10:54:37+00:00

I have locked cells in a spreadsheet using this lines of code. Range(A1:D23).Select Selection.Locked

  • 0

I have locked cells in a spreadsheet using this lines of code.

Range("A1:D23").Select
Selection.Locked = True
ActiveSheet.Protect Contents:=True

This prompts me whenever I click on a cell which is readonly to unprotect sheet from review tab and might be prompted for password.

My problem is, it is not prompting for password.How do I first set password when he wants to unprotect.Secondly I want to pass the row information that he selected to change and want to create a button when the adjoining readonly cell is used for editing.

  • 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-05-16T10:54:37+00:00Added an answer on May 16, 2026 at 10:54 am

    I get the first part of your question. You need to specify a password argument as part of the worksheet’s Protect method:

    Sub lockSheet()
        With ActiveSheet
    
            'Check sheet is not already protected
            If Not .ProtectContents Then
    
                'Clear any existing lock settings
                .Cells.Locked = False
    
                .Range("A1:D23").Locked = True
                .Protect Contents:=True, Password:="pw"
            End If
        End With
    End Sub
    

    Note that it is not necessary to select a range before modifying it, simply apply the action directly to the range.

    The password is obviously visible in plaintext, if you need to secure to any degree then you’ll also need to apply a password to the VBA project.

    To address the second part of your question, as amended in your comment:

    Private Sub Worksheet_SelectionChange(ByVal target As Range)
        If target.Locked Then
            With ActiveSheet
                .Unprotect
                If Not .ProtectContents Then
                    target.Locked = False
                    .Protect Contents:=True, Password:="pw"
                End If
            End With
        End If
    End Sub
    

    This would need added to the worksheet module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Excel (2003), I want to limit the selection of values in a cell
I have a macro in my excel workbook that updates a specific record in
so I wanted to have a table with multiple sections and each one with
I have the following working so far in C# on my Gridview called GridView1.
I have a situation in C as well as in C++ which can be
Is there a failsafe way of freeing a Delphi control? I have a TStringGrid
Good evening fellow stackers, I have a mutex and threaded related question about //
I'm using the Draggable/Droppable functionality of Jquery to allow drag-and-drop from a TreeView to
I would like to use a combobox as the itemEditor for one of the
I'm doing some heavy image manipulation in php and I would like to show

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.