Note: The other languages of the website are Google-translated. Back to English
로그인  \/ 
x
or
x
REGISTER  \/ 
x

or

Excel에서 전체 워크 시트를 보호하지 않고 지정된 셀을 잠그는 방법은 무엇입니까?

일반적으로 편집에서 셀을 잠 그려면 전체 워크 시트를 보호해야합니다. 전체 워크 시트를 보호하지 않고 셀을 잠그는 방법이 있습니까? 이 기사에서는 VBA 방법을 권장합니다.

VBA로 전체 워크 시트를 보호하지 않고 지정된 셀 잠금


VBA로 전체 워크 시트를 보호하지 않고 지정된 셀 잠금


현재 워크 시트에서 A3 및 A5 셀을 잠 가야한다고 가정하면 다음 VBA 코드를 사용하면 전체 워크 시트를 보호하지 않고도이를 달성 할 수 있습니다.

1. 시트 탭을 마우스 오른쪽 버튼으로 클릭하고 코드보기 오른쪽 클릭 메뉴에서.

2. 그런 다음 아래 VBA 코드를 복사하여 코드 창에 붙여 넣습니다. 스크린 샷보기 :

VBA 코드 : 전체 워크 시트를 보호하지 않고 지정된 셀 잠금

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 1 Then
        If Target.Row = 3 Or Target.Row = 5 Then
            Beep
            Cells(Target.Row, Target.Column).Offset(0, 1).Select
        End If
    End If
End Sub

주의 사항: 코드에서 칼럼 1, 행 = 3행 = 5 코드를 실행 한 후 현재 워크 시트의 A3 및 A5 셀이 잠 깁니다. 필요에 따라 변경할 수 있습니다.

3. 누르세요 다른 + Q 키를 동시에 닫아 응용 프로그램 용 Microsoft Visual Basic 창.

이제 A3 및 A5 셀이 현재 워크 시트에서 잠겨 있습니다. 현재 워크 시트에서 A3 또는 A5 셀을 선택하려고하면 커서가 자동으로 오른쪽 인접한 셀로 이동합니다.


관련 기사:


최고의 사무 생산성 도구

Excel 용 Kutools는 대부분의 문제를 해결하고 생산성을 80 % 향상시킵니다.

  • 재사용: 빠르게 삽입 복잡한 공식, 차트 그리고 이전에 사용한 모든 것; 셀 암호화 암호로; 메일 링리스트 생성 이메일 보내기 ...
  • 슈퍼 포뮬러 바 (여러 줄의 텍스트와 수식을 쉽게 편집 할 수 있습니다.) 레이아웃 읽기 (많은 수의 셀을 쉽게 읽고 편집합니다.) 필터링 된 범위에 붙여 넣기...
  • 셀 / 행 / 열 병합 데이터 손실없이; 셀 내용 분할; 중복 행 / 열 결합... 중복 셀 방지; 범위 비교...
  • 중복 또는 고유 선택 행; 빈 행 선택 (모든 셀이 비어 있음); 슈퍼 찾기 및 퍼지 찾기 많은 통합 문서에서; 무작위 선택 ...
  • 정확한 사본 수식 참조를 변경하지 않고 여러 셀; 참조 자동 생성 여러 시트에; 글 머리 기호 삽입, 확인란 등 ...
  • 텍스트 추출, 텍스트 추가, 위치 별 제거, 공간 제거; 페이징 부분합을 만들고 인쇄합니다. 셀 내용과 주석 간 변환...
  • 슈퍼 필터 (다른 시트에 필터 구성표 저장 및 적용) 고급 정렬 월 / 주 / 일, 빈도 등 특수 필터 굵은 기울임 꼴로 ...
  • 통합 문서와 워크 시트 결합; 키 열을 기반으로 테이블 병합; 데이터를 여러 시트로 분할; xls, xlsx 및 PDF 일괄 변환...
  • 300 개 이상의 강력한 기능. Office / Excel 2007-2019 및 365를 지원합니다. 모든 언어를 지원합니다. 기업 또는 조직에 쉽게 배포 할 수 있습니다. 전체 기능 30 일 무료 평가판. 60 일 환불 보장.
kte 탭 201905

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

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50 % 향상시키고 매일 수백 번의 마우스 클릭을 줄입니다!
officetab 하단
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.
    Aaron · 7 months ago
    Is there a way for this VBA code to run automatically every time someone opens the file?
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Hi Aaron,
      After adding the code, please save the workbook as an Excel Macro-Enabled Workbook (click File > Save As > specify a folder for the file > choose Excel Macro-Enabled Workbook from the Save as type drop-down list > Save). After that, every time when you open the file, the code works automatically.
  • To post as a guest, your comment is unpublished.
    peggywong44667799@gmail.com · 1 years ago
    I have try cannot, Hide formula without protecting.
  • To post as a guest, your comment is unpublished.
    Kasey · 2 years ago
    Hi,

    I have tried to use the code for ranges you have previously posted but it isn't working - can you advise me if I should be combining the code for ranges above or below?


    Thanks
  • To post as a guest, your comment is unpublished.
    Charlie · 2 years ago
    Hello,

    I used the code provided to Carlos and it did exactly what I wanted it to. Is there a way to have some ranges offset within the ROW to the right of the protected range (as the "Carlos" code already does), but have other ranges offset within the COLUMN to the cell directly below the protected range? I tried entering the "Carlos" code twice and changing the offset, but I received a variety of errors.

    Thank you
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Charlie,
      Sorry can't help you with that yet. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Espen · 2 years ago
    Is there any function to set for example Row 2 cell 13 to 900? Or do i need to manually punch each cell name in the code?
  • To post as a guest, your comment is unpublished.
    christophe.bourquard@gmail.com · 2 years ago
    Bonjour,
    Comment faire pour verrouiller de la cellule B8 à B10000?
    D'avance merci de votre réponse.
    Christophe
  • To post as a guest, your comment is unpublished.
    Erin · 3 years ago
    Dear Crystal,

    Thank you so much for this! It works perfectly.

    I have used the code in Carlos' comment to run the macro automatically as you open the file. I was wondering if there is a way of having an "Undo" button or something like it, that allows you to cancel that code and therefore, unlock those ranges that have been locked.

    I want those to be locked most of the time, but I would like to unlock them should I need to change any of the data. The only reason I am not protecting the whole sheet is because, if I do, it deactivates the ability to expand on tables. That in turn, expand on a line chart.

    Thanks so much for the help!
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Hi Erin,
      You can manually break the code by clicking the Break button in the Microsoft Visual Basic for Applications window to unlock those ranges. And run the code to activate it again. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    carlito2002wgn · 3 years ago
    Dear Crystal,

    Is there anyway that this macro can be run automatically upon opening the file, or upon clicking any cell. I don't want people to have to run the macro manually in order for the required ranges to be protected.

    Also, I will need to protect 12 non adjacent ranges. For example: I11:I20 and K11:K20 and M11:20 etc... How do I do this?

    Last, and this one might be asking too much, but is it possible to apply the protection to the example ranges that I provided above, BUT then extend the protection down additional rows as new ones are added? In other words, protection would be applied to I11:I20 and K11:K20 and M11:20, but a user would be able to add a new row (row 21), with new data, but once the new row is added, then the protection would apply to I11:I21 and K11:K21 and M11:21. Am I asking for the moon? :-)

    Thank you for everything that you've already provided! I can't thank you and other people like you enough for sharing the your knowledge. Amazing!
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Carlos,
      The following VBA code can help you solving the problem. Please fill in your ranges in the fourth line of the code and press the Alt + Q keys to return to the worksheet. Then please shift to other worksheet and then go back to current sheet to activate the code. Thank you for your comment.

      Dim xRg As Range
      Private Sub Worksheet_Activate()
      If xRg Is Nothing Then
      Set xRg = Union(Range("I10:I20"), Range("K10:K20"), Range("M10:M20"), Range("O10:O20"))
      End If
      End Sub
      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim I As Integer
      Dim xRgNew As Range
      Dim xRgLCell As Range
      On Error Resume Next
      Application.EnableEvents = False
      For I = 1 To xRg.Areas.Count
      Set xRgLCell = xRg.Areas.Item(I)
      Set xRgLCell = xRgLCell(xRgLCell.Count).Offset(1, 0)
      If Target.Address = xRgLCell.Address Then
      If xRgNew Is Nothing Then
      Set xRgNew = Target
      Else
      Set xRgNew = Union(xRgNew, Target)
      End If
      End If
      Next
      Set xRg = Union(xRg, xRgNew)
      Application.EnableEvents = True
      End Sub
      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      On Error GoTo Exitsub
      If (Not Intersect(xRg, Target) Is Nothing) And (Target.Count = 1) Then
      Target.Offset(0, 1).Select
      End If
      Exitsub:
      End Sub
  • To post as a guest, your comment is unpublished.
    pabloizquierdo88@gmail.com · 3 years ago
    Dear Crystal,

    You have provided me with a solution (half of it) that I have been struggling for the last few weeks, but I would need some more hints.

    How this could be applied to a table range only, not whole worksheet? Thanks in advance.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good Day,
      As the VBA code provided below, please change the specified range "H:J,4:46" to the table range you only want to lock in the worksheet.
      And cells(1,1) should be the cell outside the table range. When clicking on any cell in the table range, the cursor will be moved to that cell automatically.

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim xRg As Range
      Dim xRgEx As Range
      Dim xRgExEach As Range
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xRg = Range("H:J,4:46") 'Change the row range and column range you will lock without protecting worksheet
      Set xRgEx = Application.Intersect(xRg, Target)
      If xRgEx Is Nothing Then Exit Sub
      Cells(1, 1).Select 'Specify a cell you will shift to after selecting the locked cells
      Application.ScreenUpdating = True
      End Sub
  • To post as a guest, your comment is unpublished.
    AJ · 3 years ago
    how could i lock a range of rows, say 4-46 and columns 8 and 10
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear AJ,
      If you want to lock a range of specified rows and columns, please try the below VBA script.

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim xRg As Range
      Dim xRgEx As Range
      Dim xRgExEach As Range
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xRg = Range("H:J,4:46") 'Change the row range and column range you will lock without protecting worksheet
      Set xRgEx = Application.Intersect(xRg, Target)
      If xRgEx Is Nothing Then Exit Sub
      Cells(1, 1).Select 'Specify a cell you will shift to after selecting the locked cells
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Nikki · 9 months ago
        This is a great workaround, especially in shared workbooks where turning protection on/off is unsupported. Thank you so much.
  • To post as a guest, your comment is unpublished.
    ajay · 4 years ago
    I wanted to hide formula in Cell O1. Please inform formula for the same.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear ajay,
      If you want to hide formula in cell O1 without protecting the worksheet, please try the below VBA script.
      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Static TheFormula As String
      If Target.Address = "$O$1" Then
      With Target
      TheFormula = .Formula
      .Value = .Value
      End With
      Else
      With Range("O1")
      If Not .HasFormula Then
      .Formula = TheFormula
      End If
      End With
      End If
      End Sub

      After using the code, it seems that the formula of cell O1 is changed to formula result. Actually, it hides the formula with displaying the formula result in the Formula Bar. And the formula will display if the code is broken.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear ajay,
      For hidding formula of cells, please follow the below hyperlink to get the solution.
      https://www.extendoffice.com/documents/excel/1424-excel-hide-formulas.html