如何locking列,直到数据最后一行

我有单元格A1中提到的date,例如“May”。 我现在正在试图locking第2行的最后一列,其中提到了每个员工的joindate,并将其与A1进行比较。 如果这个单元格Z的月份是> A1,那么我试图locking该行。 不知道该怎么办。 下面的代码不帮助。

Sub Lockrow()Dim DestSh As Worksheet Dim lastrow As Long Dim i Integer

设置DestSh =表(“顾问和教师”)

使用DestSh'查找A列​​上的最后一行数据lastrow = Range(“A65536”)。End(xlUp).Row

'parse all rows For i = 6 To lastrow 'if your conditions are met If Month(.Cells(i, 26)) > Month(.Cells(1, 2)) Then .Range("A" & i).EntireRow.Cells.Locked = True 'lock the row End If Next i 

结束

结束小组

这是你正在尝试?

 Sub Sample() Dim DestSh As Worksheet Dim lastrow As Long '~~> Change this as applicable Set DestSh = Sheets("Sheet1") With DestSh If Application.WorksheetFunction.CountA(.Cells) <> 0 Then lastrow = .Columns("A:C").Find(What:="*", _ After:=.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row Else MsgBox "Insufficient rows" Exit Sub End If .Unprotect "MyPassword" .Cells.Locked = False .Range("A6:C" & lastrow).Locked = True .Protect "MyPassword" End With End Sub