简体   繁体   English

excel锁定/解锁单元格不适用于隐藏行的VBA

[英]excel locking/unlocking cells not working with VBA that hides rows

I am very new to VBA, and trying to do what i can. 我是VBA的新手,并尽我所能。

I have a workbook for different projects and the staff working on those projects, I have it so that when a staff members name is next to a project on the overview sheet, The rows associated with that project are unhidden on their personal sheet, What I want is only a few blocks of cells, within the rows of each project to have text able to be entered into them (so unlocked, with the rest locked), unfortunately when I try to do this, it stuffs up how the project rows display. 我有一个针对不同项目的工作簿,并且有从事这些项目的工作人员,所以有一个工作簿,以便当工作人员姓名在概览表上的项目旁边时,与该项目关联的行未隐藏在其个人工作表上,我希望只有几个单元格块,每个项目的行中都可以输入文本(因此已解锁,其余部分被锁定),不幸的是,当我尝试执行此操作时,它会塞满项目行的显示方式。 Can anyone give me an idea how I can do this or why this is happening? 谁能给我一个主意,我怎么做或为什么会这样?

Here are the blocks I want unlocked in the sheet (sorted by project, so hidden/ shown together): (B16:g27, i16: j28, B29:G29) (B34:g45, i34: j46, B47:G47) (B52:g63, i52: j64, B65:G65) (B70:g81, i70: j82, B83:G83) (B88:g99, i88: j100, B101:G101) (B106:117, i106: j117, B119:G119) 这是我想在工作表中解锁的块(按项目排序,因此被隐藏/一起显示):(B16:g27,i16:j28,B29:G29)(B34:g45,i34:j46,B47:G47)(B52 :g63,i52:j64,B65:G65)(B70:g81,i70:j82,B83:G83)(B88:g99,i88:j100,B101:G101)(B106:117,i106:j117,B119:G119)

any help would be hugely appreciated, I have looked through some forums and I cannot seem to find anything this specific, unless i am searching for the wrong search terms... 任何帮助将不胜感激,我浏览了一些论坛,但似乎找不到任何具体的东西,除非我搜索错误的搜索词...

Here is my VBA for showing and hiding project rows: 这是我的VBA,用于显示和隐藏项目行:

`Sub Worksheet_Calculate()
    Dim i As Long, StartRow As Long, EndRow As Long

StartRow = 13
EndRow = 29

For i = 6 To 11
    If UCase(Range("C" & i).Value) = "NO" Then
        Rows(StartRow & ":" & EndRow).EntireRow.Hidden = True
    Else
        Rows(StartRow & ":" & EndRow).EntireRow.Hidden = False
    End If
    StartRow = StartRow + 18
    EndRow = EndRow + 18
Next i

End Sub`

You can choose the cells you want to be unlocked by selecting them in the sheet and then right click on the selection --> Format cells... --> Tab Protection and there unmark the check box Locked. 您可以通过在工作表中选择要解锁的单元格来选择它们,然后右键单击选择->格式化单元格...->选项卡保护,然后取消选中已锁定复选框。

Then protect your sheet selecting Review in the ribbon and Protect Sheet. 然后保护您的工作表,在功能区中选择“查看”并选择“保护工作表”。 Or programatically Sheets("name_of_sheet").Protect "your_password" . 或以编程方式Sheets("name_of_sheet").Protect "your_password" The previous selected cells will remain unlocked. 先前选择的单元将保持解锁状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM