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. 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.