Note: The other languages of the website are Google-translated. Back to English
Vpiši se  \/ 
x
or
x
Registracija  \/ 
x

or

Kako zakleniti ali zaščititi celice po vnosu ali vnosu podatkov v Excelu?

Recimo, da imate delovni list in samo določen obseg praznih celic potrebuje vnos podatkov, po končanem vnosu podatkov pa morate celice samodejno zakleniti, da preprečite ponovne spremembe. Kako lahko to storite? Ta članek vam lahko pomaga.

Zaklenite ali zaščitite celice po vnosu ali vnosu podatkov s kodo VBA


Zaklenite ali zaščitite celice po vnosu ali vnosu podatkov s kodo VBA

Na primer, določen obseg praznih celic je A1: F8. Naredite naslednje, da zaklenete te celice po vnosu podatkov v Excelu.

1. Najprej odklenite ta obseg, izberite celice in kliknite z desno miškino tipko, nato izberite Oblikuj celice v meniju z desnim klikom in v Oblikuj celice pogovorno okno in počistite polje Zaklenjen polje pod zaščita in končno kliknite OK . Oglejte si posnetek zaslona:

2. klik pregled > Zaščitite list. In določite geslo za zaščito tega delovnega lista.

3. Z desno miškino tipko kliknite jeziček lista in izberite Ogled kode v meniju z desnim klikom. Nato kopirajte in prilepite spodnjo kodo VBA v okno Code. Oglejte si posnetek zaslona:

Koda VBA: zaklepanje ali zaščita celic po vnosu ali vnosu podatkov

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

Opombe: V kodi je "A1: F8" obseg, ki ga potrebujete za vnos podatkov; in »123« je geslo tega zaščitenega delovnega lista. Prosimo, spremenite jih po potrebi.

4. Pritisnite druga + Q tipke hkrati, da zaprete tipko Microsoft Visual Basic za aplikacije okno.

Po končanem vnosu podatkov v celice obsega A1: F8 se bodo samodejno zaklenile. Če poskusite spremeniti katero koli vsebino celic tega obsega, boste dobili hitro pogovorno okno. Oglejte si posnetek zaslona:


Sorodni članki:


Najboljša orodja za pisarniško produktivnost

Kutools za Excel rešuje večino vaših težav in poveča produktivnost za 80%

  • Ponovna uporaba: Hitro vstavite zapletene formule, grafikoni in vse, kar ste že uporabljali; Šifriraj celice z geslom; Ustvari poštni seznam in pošiljanje e-pošte ...
  • Vrstica Super Formula (enostavno urejanje več vrstic besedila in formule); Bralna postavitev (enostavno branje in urejanje velikega števila celic); Prilepite v filtrirani obseg...
  • Združi celice / vrstice / stolpce brez izgube podatkov; Vsebina razdeljenih celic; Združi podvojene vrstice / stolpce... prepreči podvojene celice; Primerjaj obsege...
  • Izberite Duplicate ali Unique Vrstice; Izberite prazne vrstice (vse celice so prazne); Super Find in Fuzzy Find v mnogih delovnih zvezkih; Naključna izbira ...
  • Natančna kopija Več celic brez spreminjanja sklica formule; Samodejno ustvarjanje referenc na več listov; Vstavi oznake, Potrditvena polja in še več ...
  • Izvleček besedila, Dodaj besedilo, Odstrani po položaju, Odstrani presledek; Ustvari in natisni vmesne seštevke strani Pretvarjanje med vsebino celic in komentarji...
  • Super filter (shranite in uporabite sheme filtrov za druge liste); Napredno razvrščanje glede na mesec / teden / dan, pogostost in drugo; Poseben filter s krepko, ležeče ...
  • Združite delovne zvezke in delovne liste; Spoji tabele na podlagi ključnih stolpcev; Razdelite podatke na več listov; Paketna pretvorba xls, xlsx in PDF...
  • Več kot 300 zmogljivih funkcij. Podpira Office / Excel 2007-2019 in 365. Podpira vse jezike. Preprosta namestitev v vašem podjetju ali organizaciji. Vse funkcije 30-dnevnega brezplačnega preskusa. 60-dnevno jamstvo za vračilo denarja.
zavihek kte 201905

Kartica Office prinaša vmesnik z zavihki v Office in poenostavi vaše delo

  • Omogočite urejanje in branje z zavihki v Wordu, Excelu, PowerPointu, Publisher, Access, Visio in Project.
  • Odprite in ustvarite več dokumentov v novih zavihkih istega okna in ne v novih oknih.
  • Poveča vašo produktivnost za 50% in vsak dan zmanjša na stotine klikov z miško!
dno pisarniške mize
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Palash Somani Good Day,
    At first, you need to set specified cells to Unlocked for editig, and then protect the worksheet. And finally apply the VBA script.
  • To post as a guest, your comment is unpublished.
    Palash Somani · 3 years ago
    cells are not even editable...what went wrong don't understand pls help
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Akshay Good Day,
    Method in this post can also help you to solve this problem.
  • To post as a guest, your comment is unpublished.
    Akshay · 3 years ago
    Hi,
    Sir i want to lock after one time input data !
    Like i am following one customer and write status , then any more employee cant edit or modify that !
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @pradip Dear pradip,
    Which Office version do you use?
  • To post as a guest, your comment is unpublished.
    pradip · 3 years ago
    @crystal No, it locks the whole range at once after a data input into a cell in the range
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Subhash Deb Dear Subhash,
    After using the code, only the edited cells are locked in the specified range. And you can still enter data into the empty cells in the specified range as you need. After fill in the blank cell, it will be locked automatically.
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Fair Dear Fair,
    Sorry can't solve this problem.
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Gourav Goya Dear Gourav,
    Sorry can't solve this problem.
  • To post as a guest, your comment is unpublished.
    crystal · 3 years ago
    @Stacy Dear Stacy,
    The same problem does not appear in my case. The code prevent users from entering as well as deleting data from the specified range. Would you provide your Office version for further testing?
  • To post as a guest, your comment is unpublished.
    Fair · 3 years ago
    Thanx for the coding, but I've a problem to put 2 coding in 1 sheet, pls help.
  • To post as a guest, your comment is unpublished.
    Subhash Deb · 4 years ago
    i like to lock only the edited cells. once i enter any data to the empty cells, i require to lock the edited cell to be automitically locked but not the empty cells.
  • To post as a guest, your comment is unpublished.
    Jezamiah · 4 years ago
    For anyone who might have stumbled here since this comment.
    If you are having to unlock the worksheet EVERYTIME you fill in a cell then you need to first,

    - Unlock the spreadsheet
    - Highlight the area of the worksheet the code applies over
    - Right-click and go to 'format cells'
    - Go to the far right tab called 'Protection' and UNCHECK the 'Locked' section (Even if It appears as a solid fill instead of a tick)

    After that you will be able to enter data in multiple cells without having to unlock everytime. Bear in mind if you need to revisit locked cells to delete or edit information you may need to repeat the steps above.

    Hope this helps.
  • To post as a guest, your comment is unpublished.
    Stacy · 4 years ago
    I tried the code and seemed to work somewhat. It does however allow me to delete the date entered into the cell but only stops me when I try to enter something else. Is there a way to keep data from being deleted?
  • To post as a guest, your comment is unpublished.
    Gourav Goya · 4 years ago
    Hello Sir ,

    I am facing one problem with the same code while using this code with other cobe in VBA.

    Please suggest me some solution

    Thanks and Regards
    Gourav
  • To post as a guest, your comment is unpublished.
    rsrneuro · 4 years ago
    Thanks for the code. Please let me know how to do auto lock the cells (similar to the ones listed by you) ONLY AFTER saving the file
  • To post as a guest, your comment is unpublished.
    spence · 4 years ago
    Try this code instead:


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range

    Set MyRange = Intersect(Range("A1:D100"), Target)
    If Not MyRange Is Nothing Then
    Sheets("Sheet1").Unprotect password:="hello"
    MyRange.Locked = True
    Sheets("Sheet1").Protect password:="hello"
    End If
    End Sub


    And remember to change range (A1:D100), password (hello) and sheet (Sheet1) names/numbers if it does not match the above :)
  • To post as a guest, your comment is unpublished.
    Nitin Ingole · 4 years ago
    This is not working when it reopen excel file please help
  • To post as a guest, your comment is unpublished.
    Pravallika p · 4 years ago
    Hello,

    I have a spreadsheet with the range A3:AN219, i would like to protect this range as and when input complete.
    Please help me on this. I tried above code but it is not working for me