宏VBA仅当行不';t包含“t”字;保留;在BR列中
我正在尝试在受密码保护的工作表上写入宏,该工作表允许用户删除特定行,但前提是列BR中的单元格不包含单词“keep”,并且如果用户选择了无法删除的行,则会弹出错误消息,说明“您选择了无法删除的行。请选择其他行” 我已经计算出了第一部分(如下),但不知道如何告诉它仅在“keep”不在列BR中时删除该行。我对VBA很陌生,通过谷歌混日子,但我正式被卡住了宏VBA仅当行不';t包含“t”字;保留;在BR列中,vba,excel,delete-row,Vba,Excel,Delete Row,我正在尝试在受密码保护的工作表上写入宏,该工作表允许用户删除特定行,但前提是列BR中的单元格不包含单词“keep”,并且如果用户选择了无法删除的行,则会弹出错误消息,说明“您选择了无法删除的行。请选择其他行” 我已经计算出了第一部分(如下),但不知道如何告诉它仅在“keep”不在列BR中时删除该行。我对VBA很陌生,通过谷歌混日子,但我正式被卡住了 Dim x As Integer On Error Resume Next ActiveSheet.Unprotect Password:="pas
Dim x As Integer
On Error Resume Next
ActiveSheet.Unprotect Password:="password"
x = InputBox("Please Enter the Row Number")
Range("A" & x).EntireRow.Delete Shift:=xlUp
ActiveSheet.Protect Password:="password"
End Sub
这应该做到:
Sub not_mentioned()
Dim x As Long
ActiveSheet.Unprotect Password:="password"
x = InputBox("Please Enter the Row Number")
If Not UCase(Cells(x, 70)) Like "*KEEP*" Then
Range("A" & x).EntireRow.Delete Shift:=xlUp
Else
MsgBox "You have chosen a row that cannot be deleted." & Chr(10) & "Please choose another row"
End If
ActiveSheet.Protect Password:="password"
End Sub
下面是一种方法,要求用户使用
Application.InputBox
选择要删除的行上的单元格
选项比较
文本使其不区分大小写。即保持
=保持
。还不清楚单元格是将Keep
与字符串混合,还是只包含单词Keep
。无论哪种方式,看起来你都有一个解决方案来解决这两个问题
使用类似于的
来预测需求!我差点因为不符合资格而收回;)(半开玩笑)感谢堆-这已经起作用了:)可以将这些更改为删除一系列行,即输入开始行和输入完成行,但如果只删除一行,则会进行相同的检查吗?如果需要多个输入,则应进行简单的检查。试试看,如果你有困难就回来。非常感谢你的帮助,我已经让它工作了:)
Option Explicit
Option Compare Text
Sub DeleteMe()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
Dim TargetRow As Range
On Error Resume Next 'If user hits "Cancel" on Input Box
Set TargetRow = Application.InputBox("Please Select a Cell on Row to Delete", Type:=8)
On Error GoTo 0
If Not TargetRow Is Nothing Then
If ws.Cells(TargetRow.Row, "BR") = "keep" Then
MsgBox "You have chosen a row that cannot be deleted. Please choose another row", vbCritical
Else
ws.Unprotect "password"
ws.Cells(TargetRow.Row, 1).EntireRow.Delete
ws.Protect "password"
End If
End If
End Sub