簡體   English   中英

讀取單元格值的宏,在表中查找是否存在該值,如果存在,則刪除表行並向上移動

[英]Macro to read a cell value, find in a table if such value exits, if it does, delete table row and shift up

忘記密碼:

它返回對象變量錯誤。 我嘗試記錄一個宏,但是“查找”無法通過復制和粘貼正常運行,然后,宏記錄了我實際所在的行,而不是變量。

除了查找之外,我還嘗試了“ Cells.AutoFilter Field:= 2,Criteria1:= x”,但是這將返回Autofilter范圍類失敗。 我被卡住了。 希望能幫助到你。

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

這應該使您開始:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM