메인 컨텐츠로 가기

Excel에서 특정 셀 내용이 삭제되는 것을 방지하는 방법은 무엇입니까?

이 기사에서는 특정 셀 내용이 Excel에서 삭제되는 것을 방지하는 방법에 대해 설명합니다. 이 기사의 방법으로 달성 할 수 있습니다.

워크 시트를 보호하여 특정 셀 내용이 삭제되지 않도록 방지
VBA 코드를 사용하여 특정 셀 내용이 삭제되지 않도록 방지


워크 시트를 보호하여 특정 셀 내용이 삭제되지 않도록 방지

기본적으로 워크 시트의 모든 셀은 잠겨 있습니다. 특정 셀 내용이 삭제되는 것을 방지하고 보호 후 다른 셀을 편집 가능하게하려면 다음과 같이하십시오.

1. 을 클릭합니다 전체 워크 시트를 선택하려면 워크 시트의 왼쪽 상단 모서리에있는 버튼을 클릭합니다. 그런 다음 Ctrl 키 + 1 키를 눌러 셀 서식 대화 상자.

2. 팝업에서 셀 서식 대화 상자에서 고정 옵션 아래의 보호 탭을 클릭 한 다음 OK 단추. 스크린 샷보기 :

3. 내용을 삭제하지 않으려는 셀을 선택하고 Ctrl 키 + 1 개의 열쇠를 여는 셀 서식 대화 상자를 다시 확인하고 고정 옵션 아래의 보호 탭을 클릭 한 다음 OK 버튼을 클릭합니다.

4. 이제 검토 > 시트 보호을 클릭 한 다음 두 항목 모두에서 암호를 지정하고 확인하십시오. 시트 보호 비밀번호 확인 대화 상자.

이제 워크 시트가 보호됩니다. 그리고 지정된 셀 내용은 더 이상 삭제되지 않습니다.


VBA 코드를 사용하여 특정 셀 내용이 삭제되지 않도록 방지

위의 두 가지 방법 외에도 VBA 코드를 실행하여 워크 시트에서 특정 셀 내용이 삭제되는 것을 방지 할 수 있습니다. 다음과 같이하십시오.

1. 삭제하지 않을 셀 내용이 포함 된 워크 시트를 열고 시트 탭을 마우스 오른쪽 단추로 클릭 한 다음 코드보기 오른쪽 클릭 메뉴에서.

2. 아래 VBA 코드를 복사하여 코드 창에 붙여 넣으십시오. 응용 프로그램 용 Microsoft Visual Basic 창.

VBA 코드 : Excel에서 특정 셀 내용이 삭제되지 않도록 방지

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A1:E7")) Is Nothing Then Exit Sub
    On Error GoTo ExitPoint
    Application.EnableEvents = False
    If Not IsDate(Target(1)) Then
        Application.Undo
        MsgBox " You can't delete cell contents from this range " _
        , vbCritical, "Kutools for Excel"
    End If
ExitPoint:
    Application.EnableEvents = True
End Sub

주의 사항: 코드에서 A1 : E17은 셀 내용이 삭제되지 않도록하는 범위입니다. 필요에 따라 범위를 변경할 수 있습니다.

지금부터 A1 : E17 범위에서 셀 내용을 삭제하려고하면 Excel 용 Kutools 아래 스크린 샷과 같은 대화 상자를 클릭하십시오. OK 버튼을 클릭합니다.


관련 기사:

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (18)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Hi,

This is exactly what I was looking for, but it doesn't work for me...
This says: "End Sub expected"

Can you help me ?

Thanks :)
This comment was minimized by the moderator on the site
This is great. I was wondering if this was an option and sure enough it was. Thank you for the very easy instructions.

Andres S.
Rated 5 out of 5
This comment was minimized by the moderator on the site
No, I meant NOT to allow deletion (without protecting the wks or wkb).

It is nice the above works at Wks level.

If there is something to make it work at wkb level it would be even better (I have many sheets)

G
This comment was minimized by the moderator on the site
Is it possible to do something similar at workbook level?

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1:M7000")) Is Nothing Then Exit Sub
On Error GoTo ExitPoint
Application.EnableEvents = False
If Not IsDate(Target(1)) Then
Application.Undo
MsgBox " You can't delete cell contents from this range " _
, vbCritical, "Kutools for Excel"
End If
ExitPoint:
Application.EnableEvents = True
End Sub
This comment was minimized by the moderator on the site
Hi Gelu,
Do you mean to prevent the range "A1:M7000" from being deleted in all worksheets of the current workbook?
This comment was minimized by the moderator on the site
Thank you for the valuable information.
Regarding the below VBA:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1:E7")) Is Nothing Then Exit Sub
On Error GoTo ExitPoint
Application.EnableEvents = False
If Not IsDate(Target(1)) Then
Application.Undo
MsgBox " You can't delete cell contents from this range " _
, vbCritical, "Kutools for Excel"
End If
ExitPoint:
Application.EnableEvents = True
End Sub

The above will allow execution within a certain specified range. It does not allow the addition of new rows. Is there a way that new rows can be added yet maintaining the same protection.
thanks and regards
This comment was minimized by the moderator on the site
Hi Oussama Abou faraj,
After trying with various methods, I can't seem to get this to work. After adding a new row, the area will be locked Immediately and the newly inserted cell cannot be edited.
This comment was minimized by the moderator on the site
Hello, this code works well, however deleting row/collumn will bypass it. Is there any workaround to this? Cheers, David.
This comment was minimized by the moderator on the site
Hi David,
Which Excel version are you using? I have tried the code, entire rows and columns in the specified range can't be deleted after applying the code.
This comment was minimized by the moderator on the site
"Prevent specific cell contents from being deleted by protecting the worksheet"I did as per your guideline, still cell information could be deleted i.e. protection does not work. Any solution.
This comment was minimized by the moderator on the site
Hi Ahsan,
Did you apply the VBA method?
You need to add the VBA to the worksheet code window. Supposing the cell contents you want to protect are in Sheet9, please right click the sheet tab and select View Code from the context menu, and then directly copy the code into the code window as the below image shown.
This comment was minimized by the moderator on the site
VBA Code - Great Tip thanks

Is there a VBA code to Prevent specific cell contents from being modified AND deleted in Excel?
Usual protecting sheet does not work for me as I lose the ability to sort data?

Thanks in advance - Neil
This comment was minimized by the moderator on the site
If you don't wan to look your sheet or write VBA code, then I use a simple technique that prevents from any override except for when they use the "DELETE" key (backspace won't be allowed, but Delete is hard to stop). What I did is added a data validation with the following settings:

1) Allow --> List

2) uncheck "Ignore blank" and "in-cell dropdown"

3) In the source enter two double quotes (i.e., "")

4) In Error Alert tab, check "Show error alter after invalid data is entered", select "Stop" for style, then enter an error message and description (e.g., Don't override)
This comment was minimized by the moderator on the site
Hi,
Thanks for sharing.
This comment was minimized by the moderator on the site
Hi there,

I just tried the VBA script and while it works really well in most situations. However it doesn't work when you tab from an editable cell into the non-editable column/cell. The problem arises in that it throws the error message up - as commanded - but it doesn't keep the data that was entered in the original, editable cell which was tabbed from.

Would you have an amendment to the script so that it accepts the data in the editable cell when you tab into un-editable?

Cheers
This comment was minimized by the moderator on the site
Good day,
I tried as you mentioned in your case, but no error throws. Would you provide a screenshot of your case or tell me your Office version?
Thanks for your comment.
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