locking特定月份的行

我的数据有单元格A1包含月。

A2:Z999:员工详情。 P栏:joindate。

我想编写代码,当P> A1时,它应该locking该雇员的行,因为它是旧数据。 只有没有date的行或空的999行应该是空的。

请帮忙! 现在我的代码在下面locking一切。

Dim DestSh As Worksheet Dim lastrow As Long Set DestSh = Sheets("Consultant & Teacher") With DestSh If Application.WorksheetFunction.CountA(.Cells) <> 0 Then lastrow = .Columns("A:z").Find(What:="*", _ After:=.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row Else MsgBox "Insufficient rows" End If If Range("A1").Value = "April" Then .Unprotect Password:="MyPassword" .Cells.Locked = False .Range("A2:Z" & lastrow).Locked = True 

我不太清楚你想用现有的代码来完成什么,但是纯粹根据你的解释,我认为这应该是个诀窍:

 Dim DestSh As Worksheet Dim lastrow As Long Dim i As Integer Set DestSh = Sheets("Consultant & Teacher") With DestSh 'finds the last row with data on A column lastrow = Range("A65536").End(xlUp).Row 'parse all rows For i = 2 To lastrow 'if your conditions are met If Month(.Cells(i, 16)) > Month(.Cells(1, 1)) Then .Range("A" & i).EntireRow.Cells.Locked = True 'lock the row End If Next i End With