简体   繁体   English

根据列标题和行标题解锁单元格?

[英]Unlock cells based on both column and row headers?

I have a table which looks like this (it changes dynamically).我有一个看起来像这样的表(它动态变化)。 桌子

I am trying to make a macro which would unlock only the "light yellow" cells = row 1 contains "Forecast" as a value and column I contains "Actual" as a value.我正在尝试制作一个宏,它只能解锁“浅黄色”单元格 = 第 1 行包含“预测”作为值,而列 I 包含“实际”作为值。 I would later protect the sheet so the user would be able to change value only in these cells.我稍后会保护工作表,以便用户只能在这些单元格中更改值。

In conditional formatting I use this formula: =(INDIRECT(ADDRESS(1;COLUMN();4))="Forecast")*(INDIRECT(ADDRESS(ROW();COLUMN($I$1);4))="Actual") But I've failed to make something like this work in VBA.在条件格式中,我使用这个公式: =(INDIRECT(ADDRESS(1;COLUMN();4))="Forecast")*(INDIRECT(ADDRESS(ROW();COLUMN($I$1);4))="Actual")但我没能在 VBA 中做这样的事情。

Just in case anyone wondered how to do it.以防万一有人想知道如何做到这一点。

Sub Lock_Cells()
Dim startCol As Long
startCol = WorksheetFunction.Match("Forecast", Range("1:1"), 0) 'Define in which column Forecast starts

Dim i As Long 
For i = 2 To Range("I" & Rows.Count).End(xlUp).Row
    If Cells(i, "I").Value = "Actual" Then 'Loop through values in column I
        Range(Cells(i, startCol), Cells(i, "U")).Locked = False 'Unlock cells
    End If
Next i
End Sub

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

相关问题 根据一行中单元格的颜色返回多个列标题 - Return multiple column headers based on the color of the cells within a row 我需要根据一行中单元格的值从一个表返回多个列标题 - I need to return multiple column headers from a table based on the value of the cells within a row 在两个单元上自动拟合行高:具有合并单元格的列和具有单个单元格的列 - Autofit Row Height on Both: Column with Merged Cells AND Column with Single Cells 是否可以基于另一列/单元格对单元格的行/列进行着色? - Is it Possible to Color a Column/Row of Cells based on another Column/Row of Cells? 根据列标题将单元格粘贴到特定行中 - Paste cells in specific row based on column header 当单元格中有文本时,返回一行中的列标题列表 - Return a list of column headers across a row when cells have text 从另一个工作表的单元格列替换第一行中的标题名称 - Replace Headers name in the first row from the cells column of another sheet 根据同一行中的其他单元格日期突出显示列中的单元格 - Highlighting cells in a column based on other cells dates in the same row 基于行ID的特定列标题的行数据 - Row data for specific column headers based on row ID 根据列标题动态求和行值? -Excel - Dynamically sum row values based on column headers? - Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM