删除表行时,查找单元格引用并在其他代码中使用它来运行宏vba

时间:2018-03-22 21:25:47

标签: excel excel-vba vba

Feeder Table 我希望我的代码工作如下:

用户从Feeder表中删除一行后,另一个表中该行的所有记录也将从Storage表中删除: Storage Table

我已经在存储表工作表上使用了代码:

Sub TestDeleteRows()
Dim rFind As Range
Dim rDelete As Range
Dim strSearch As String

strSearch = "YYY" 'Change to the code ActiveCell.Value or some variation
Set rDelete = Nothing

Application.ScreenUpdating = False

With Sheet2.Columns("C:C")
    Set rFind = .Find(strSearch, LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlPrevious, MatchCase:=False)
    If Not rFind Is Nothing Then
        Do
            Set rDelete = rFind
            Set rFind = .FindPrevious(rFind)
            If rFind.Address = rDelete.Address Then Set rFind = Nothing
            rDelete.EntireRow.Delete
        Loop While Not rFind Is Nothing
    End If
End With
Application.ScreenUpdating = True
End Sub

我想要" YYY"作为Feeder表上代码生成的输入。 用户尝试删除行后,会弹出一个消息框,询问他们是否确定。 然后代码将复制项目名称并在上面的代码中使用该名称代替" YYY"。

我目前的代码如下,但根本不起作用:

Sub DeleteRow()
    Dim OnDelete As Integer
    Dim Dprompt As String

    OnDelete = MsgBox("Are you sure?", vbOKCancel)
    Dprompt = "Delete Project?"

    With Sheet1
        If Selection.EntireRow.Delete Then
            MsgBox "Are you Sure?" & OnDelete
            If OnDelete = 0 Then
            End If

        Else: OnDelete = 1
        TestDeleteRows
        ProjectName = YYY


End If
End With
End Sub

我能帮忙吗?

0 个答案:

没有答案