vba 宏读取单元格值,在表格中查找是否存在此类值,如果存在,则删除表格行并向上移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20036149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Macro to read a cell value, find in a table if such value exits, if it does, delete table row and shift up
提问by Rafael Alves
Forgot the code:
忘记密码了:
It returns object variable error. I tried to record a macro but Find doesnt function properly with copy and paste, and then, macro records the actual row I′m in, not a variable.
它返回对象变量错误。我试图记录一个宏,但 Find 无法通过复制和粘贴正常运行,然后,宏记录了我所在的实际行,而不是变量。
Instead of Find, I also tried " Cells.AutoFilter Field:=2, Criteria1:=x" but that would return Autofilter range class failed. I′m stuck. Hope it helps.
我还尝试了“Cells.AutoFilter Field:=2, Criteria1:=x”,而不是 Find,但这会返回 Autofilter range class failed。我被卡住了。希望能帮助到你。
Sub alta()
'
' alta Macro
x = Range("I3").Select
Selection.Copy
Selection.Find(What:=x, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
True, SearchFormat:=False).Activate
Application.CutCopyMode = False
Selection.EntireRow.Delete
Range("I3").Select
Selection.ClearContents
End Sub
采纳答案by Portland Runner
This should get you started:
这应该让你开始:
Private Sub CommandButton1_Click()
If Range("I3").Value <> "" Then
If IsError(Application.Match(Range("I3"), Range("B3:B20"), 0)) Then
MsgBox ("No Match")
Else
foundRow = Application.Match(Range("I3"), Range("B3:B20"), 0) + 2
Range("A" & foundRow & ":B" & foundRow).Delete Shift:=xlUp
End If
End If
End Sub