Lock and unlock cells with a password

KlausW

Active Member
Joined
Sep 9, 2020
Messages
396
Office Version
  1. 2016
Platform
  1. Windows
Hi

Is it possible to make a VBA code that can lock and unlock cells in range D9 to D3669 with a password?

So, when someone try to write in a cell, a messenger box will be shown on the screen. Head line shout be "Limited access", an text "enter password to change this cell".

I use this VBA-code, I got by a friend to Lock a single cell. Maybe it can inspire.

All help will be appreciated.

Best regards

Klaus W

VBA Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 Static Passed As Boolean
    Dim P$
        If Target.Address <> "$A$7" Or Passed Then Exit Sub
    Do
        P = InputBox(vbLf & vbLf & "Indtast adgangskode for at ændre denne celle:", "Begrænset adgang")
        If P = "" Then Target(1, 2).Select: Exit Sub
    Loop Until P = "A096"
        Passed = True
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top