[英]Restrict deletion of rows in specific range
我有通过选择特定单元格来删除行的简单代码。 问题是它不应该被允许删除A1:AZ7
范围内的行我想我需要这个操作的 if 语句? 它应该是什么?
Private Sub CommandButton24_Click()
ThisWorkbook.Worksheets("GanttChart").Unprotect Password:="123456"
Dim MyRange As Range
Dim TestRange As Range
Set TestRange = ThisWorkbook.Worksheets("GanttChart").Range("A1:AZ7")
Set MyRange = ' slected cell
If Not Application.Intersect(MyRange, TestRange) Is Nothing Then
ThisWorkbook.Worksheets("GanttChart").Range("A" & ActiveCell.Row).Rows(1).EntireRow.Delete
End If
ThisWorkbook.Worksheets("GanttChart").Protect Password:="123456"
End Sub
Private Sub CommandButton24_Click()
With ThisWorkbook.Worksheets("GanttChart")
.Unprotect Password:="123456"
Dim MyRange As Range
Dim TestRange As Range
Set TestRange = .Range("A1:AZ7")
Set MyRange = Selection ' U Can select many cells
If Application.Intersect(MyRange.EntireRow.Rows, TestRange.EntireRow.Rows) Is Nothing Then
'ThisWorkbook.Worksheets("GanttChart").Range("A" & ActiveCell.Row).Rows(1).EntireRow.Delete
MyRange.EntireRow.Delete
End If
.Protect Password:="123456"
End With
End Sub
Private Sub CommandButton24_Click()
ThisWorkbook.Worksheets("GanttChart").Unprotect Password:="123456"
Dim MyRange As Range
Dim TestRange As Range
Set TestRange = ThisWorkbook.Worksheets("GanttChart").Range("A1:AZ7")
Set MyRange = ActiveCell
If Not Application.Intersect(MyRange, TestRange) Is Nothing Then
Else
ThisWorkbook.Worksheets("GanttChart").Range("A" & ActiveCell.Row).Rows(1).EntireRow.Delete
End If
ThisWorkbook.Worksheets("GanttChart").Protect Password:="123456"
End Sub
目前,您正在检查范围是否不相交。 再试一次,不要在 if 语句中加上“not”。 not 和 is nothing 相互抵消。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.