Ana içeriğe atla

Excel'de veri girişi veya girişi yapıldıktan sonra hücreleri nasıl kilitleyebilir veya koruyabilirim?

Bir çalışma sayfanız olduğunu ve yalnızca belirli bir boş hücre aralığının veri girişi gerektirdiğini varsayarsak ve veri girişini tamamladıktan sonra, değişiklikleri tekrar önlemek için hücrelerin otomatik olarak kilitlenmesi gerekir. Bunu başarmak için nasıl yapabilirsiniz? Bu makale size yardımcı olabilir.

Veri girişinden veya VBA kodu ile girildikten sonra hücreleri kilitleyin veya koruyun


Veri girişinden veya VBA kodu ile girildikten sonra hücreleri kilitleyin veya koruyun

Örneğin, belirli boş hücre aralığı A1: F8'dir. Excel'de veri girişinden sonra bu hücreleri kilitlemek için lütfen aşağıdaki işlemleri yapın.

1. Lütfen önce bu aralığın kilidini açın, hücreleri seçin ve sağ tıklayın, ardından şunu seçin: biçim Hücreler sağ tıklama menüsünde ve biçim Hücreler iletişim kutusu, işaretini kaldırarak Kilitli altındaki kutuyu koruma sekmesine tıklayın ve son olarak OK buton. Ekran görüntüsüne bakın:

2. tık Değerlendirme > Koruma Sayfası. Ve bu çalışma sayfasını korumak için bir parola belirleyin.

3. Sayfa sekmesine sağ tıklayın, Kodu Görüntüle sağ tıklama menüsünden. Ardından aşağıdaki VBA kodunu Kod penceresine kopyalayıp yapıştırın. Ekran görüntüsüne bakın:

VBA kodu: Veri girişinden veya girişinden sonra hücreleri kilitleyin veya koruyun

Dim mRg As Range
Dim mStr As String

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("A1:F8"), Target) Is Nothing Then
    Set mRg = Target.Item(1)
    mStr = mRg.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range
    On Error Resume Next
    Set xRg = Intersect(Range("A1:F8"), Target)
    If xRg Is Nothing Then Exit Sub
    Target.Worksheet.Unprotect Password:="123"
    If xRg.Value <> mStr Then xRg.Locked = True
    Target.Worksheet.Protect Password:="123" 
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Range("A1:F8"), Target) Is Nothing Then
    Set mRg = Target.Item(1)
     mStr = mRg.Value
End If
End Sub

not: Kodda, "A1: F8" veri girmeniz gereken aralıktır; ve "123" bu korumalı çalışma sayfasının şifresidir. Lütfen ihtiyaç duyduğunuzda değiştirin.

4. Basın Ara Toplam + Q kapatmak için aynı anda tuşları Uygulamalar için Microsoft Visual Basic pencere.

A1: F8 aralığındaki hücrelere veri girmeyi bitirdikten sonra, bunlar otomatik olarak kilitlenir. Ve bu aralığın herhangi bir hücre içeriğini değiştirmeye çalışırsanız, bir hızlı iletişim kutusu alırsınız. Ekran görüntüsüne bakın:


İlgili Makaleler:

En İyi Ofis Üretkenlik Araçları

🤖 Kutools AI Yardımcısı: Aşağıdakilere dayalı olarak veri analizinde devrim yaratın: Akıllı Yürütme   |  Kodunu oluşturun  |  Özel Formüller Oluşturun  |  Verileri Analiz Edin ve Grafikler Oluşturun  |  Kutools İşlevlerini Çağır...
Popüler Özellikler: Yinelenenleri Bul, Vurgula veya Tanımla   |  Boş Satırları Sil   |  Veri Kaybı Olmadan Sütunları veya Hücreleri Birleştirin   |   Formülsüz Tur ...
Süper Arama: Çoklu Ölçütlü VLookup    Çoklu Değer VLookup  |   Birden Çok Sayfada VLookup   |   Bulanık Arama ....
Gelişmiş Açılır Liste: Hızla Açılır Liste Oluşturun   |  Bağımlı Açılır Liste   |  Çoklu Seçim Açılır Liste ....
Sütun Yöneticisi: Belirli Sayıda Sütun Ekleme  |  Sütunları Taşı  |  Gizli Sütunların Görünürlük Durumunu Değiştir  |  Aralıkları ve Sütunları Karşılaştırın ...
Öne Çıkan Özellikler: Izgara Odağı   |  Tasarım görünümü   |   Büyük Formül Çubuğu    Çalışma Kitabı ve Sayfa Yöneticisi   |  Kaynak Kütüphanesi (Otomatik metin)   |  Tarih Seçici   |  Çalışma Sayfalarını Birleştirin   |  Hücreleri Şifrele/Şifresini Çöz    E-postaları Listeye Göre Gönder   |  Süper Filtre   |   Özel Filtre (kalın/italik/üstü çizili filtre...) ...
En İyi 15 Araç Seti12 Metin Tools (Metin ekle, Karakterleri Kaldır, ...)   |   50+ Grafik Türleri (Gantt şeması, ...)   |   40+ Pratik Formüller (Yaşı doğum gününe göre hesapla, ...)   |   19 sokma Tools (QR Kodunu Girin, Yoldan Resim Ekle, ...)   |   12 Dönüştürme Tools (Sayılardan Kelimelere, Para Birimi Dönüştürme, ...)   |   7 Birleştir ve Böl Tools (Gelişmiş Kombine Satırları, Bölünmüş hücreler, ...)   |   ... ve dahası

Kutools for Excel ile Excel Becerilerinizi Güçlendirin ve Daha Önce Hiç Olmadığı Gibi Verimliliği Deneyimleyin. Kutools for Excel, Üretkenliği Artırmak ve Zamandan Tasarruf Etmek için 300'den Fazla Gelişmiş Özellik Sunar.  En Çok İhtiyacınız Olan Özelliği Almak İçin Buraya Tıklayın...

Açıklama


Office Tab, Office'e Sekmeli Arayüz Getirir ve İşinizi Çok Daha Kolay Hale Getirir

  • Word, Excel, PowerPoint'te sekmeli düzenlemeyi ve okumayı etkinleştirin, Publisher, Access, Visio ve Project.
  • Yeni pencereler yerine aynı pencerenin yeni sekmelerinde birden çok belge açın ve oluşturun.
  • Üretkenliğinizi% 50 artırır ve her gün sizin için yüzlerce fare tıklamasını azaltır!
Comments (75)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Good day, what I want to do is quite similar to the presented code however, the code only caters for individual data entry. My case is that I have a data entry interface but the given code doesn't follow the formulas before the selected cells which is substantial in my situation. Please, help me to resolve this. Thank you so much :D
This comment was minimized by the moderator on the site
I want to lock a particular range after an entry and allow only one entry in that range.
the range already contains a data validation.
This comment was minimized by the moderator on the site
Hi Rakesh Chand,
Assuming the specific range is A1:D7, when you select an entry in any data validation of that range, the worksheet will be protected.
Please apply the following VBA code to get it done.

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20220831
    Dim xRg As Range
    Dim Rg As Range
    On Error Resume Next
    Set Rg = Range("A1:D7")
    Set xRg = Intersect(Rg, Target)
    If xRg Is Nothing Then Exit Sub
       
    Rg.Locked = True
    
        Rg.Worksheet.Protect Password:="123"
    
End Sub
This comment was minimized by the moderator on the site
доброго времени суток!
Возможно ли с помощью кода сделать следующие?
Есть таблица, к примеру 6 столбцов, в которую последовательно вносят данные в 5 столбов (присутствует режим "выбор из списка данных" и формулы), а в 6-ом выбирается фамилия вносившего. Возможно ли блокировать полностью строку с внесенными данными, только после заполнения последней ячейке в этой строке (6-ой столбец)?
Выше указанный способ блокирует ввод данных в ячейки где есть выбор из списка данных на всём листе.
Если есть такой вариант, буду очень признателен за код.
Заранее Спасибо!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi I am having an error with the deletion. Whenever I tried to click the delete the record a pop up will say "Microsoft Excel will permanently delete this sheet. Do you want to continue'.

Here's the code that I am using:

Sub Deletion()

Dim iRow As Long
Dim iSerial As Long


iSerial = Application.InputBox("Please enter Serial No. to delete the record.", "Delete", , , , , , 1)

On Error Resume Next

iRow = Application.WorksheetFunction.IfError _
(Application.WorksheetFunction.Match(iSerial, Sheets("Database").Range("A:A"), 0), 0)

On Error GoTo 0

If iRow = 0 Then

MsgBox "No record found.", vbOKOnly + vbCritical, "No Record"
Exit Sub

End If

Sheets("Database").Cells(iRow, 1).EntireRow.Delete Shift:=xlUp

End Sub


Please help me fix it. Thanks!
This comment was minimized by the moderator on the site
Hi guys. I need help and I'm new with VBA.
Say, I have Column BH with dropdown choices for Confirmed, Pending, and Cancelled.
All columns must remain unlocked for editing except for Columns A, BD, BE, and BF which must remain lock all the time.
If "Confirmed" is selected on Column BH, I want to lock the entire row before/next to it. Then, a password must be used if I want to edit the "Confirmed" row.
Can someone help me with this please?
Thanks in advance.

This comment was minimized by the moderator on the site
Good day...
Your tutorial is great!
I ran across a Run-Time error '13': during selection change if I select entire row. What is the turn-around for this? Any insight is much appreciated.
This comment was minimized by the moderator on the site
Hi,Which Excel version are you using?
This comment was minimized by the moderator on the site
Hi, This is all new to me. The formula is great. I want to lock cells D6:D36, H6:H35 & L6:L35 but can't get this to work. any help would be greatly appreciated.
This comment was minimized by the moderator on the site
Hi simon,If you want to lock cells in D6:D36, H6:H35 and L6:L35 separately after finish entering data in each range. Please do as follows.1. Select these three ranges by holding the Ctrl key;2. Do as the post described in step 1 to unlock these three ranges;3. Protect your worksheet with a password (Here my password is 123. This password will be used in the below code);4. Right click the sheet tab and then paste the below VBA code into the Code editor, and then press Alt + Q keys to close the Microsoft Visual Basic for Applications window.Notes: 1) In the code, you can change the ranges and password as you need;2)After pressing Alt + Q keys to close the code window, you need to shift to another worksheet and then go back to current sheet to make the code work. Otherwise, error will be occurred.<div data-tag="code">Dim mRg As Range
'Updated by Extendoffice 20201030
Dim mStr As String
Dim mStrAddress As String
Dim mArr
Private Sub Worksheet_Activate()
On Error Resume Next
Erase mArr()
mStrAddress = "D6:D36,H6:H35,L6:L35"
mArr = Split(mStrAddress, ",")
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim xI As Integer
For xI = 0 To UBound(mArr)
If Not Intersect(Range(mArr(xI)), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
Exit For
End If
Next
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
Dim xI As Integer
On Error Resume Next
For xI = 0 To UBound(mArr)
Set xRg = Null
Set xRg = Intersect(Range(mArr(xI)), Target)
If Not (xRg Is Nothing) Then
Target.Worksheet.Unprotect Password:="123"
If xRg.Value <> mStr Then xRg.Locked = True
Target.Worksheet.Protect Password:="123"

End If
Next
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xI As Integer
On Error Resume Next
For xI = 0 To UBound(mArr)
If Not Intersect(Range(mArr(xI)), Target) Is Nothing Then
Set mRg = Target.Item(1)
mStr = mRg.Value
End If
Next
End Sub
This comment was minimized by the moderator on the site
If Not Intersect(Range("CUSTOMER!"), Target) Is Nothing Then
I got an error. I want to protect the whole sheet
This comment was minimized by the moderator on the site
Good afternoon ... thank you again for this great resource. I do have one question. We have a shared document that is used by multiple users for input purposes. We have noticed that if User A enters data in a given cell, User A cannot edit per the code above (which is exactly what we want) but User B who the document is also shared with can delete the data that User A entered. Is there a revision for the code above that could be included in a shared document that has multiple users that are entering data.
This comment was minimized by the moderator on the site
Hi
I want to auto lock cell while i'm saving my worksheet
Can you help me how to do this in vba
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations