Delete Data Entries Based on Table Row Deletion

theteerex

Board Regular
Joined
Mar 2, 2018
Messages
102
I have two tables, one that feeds the other based on user entries.
This the only interaction, add data to one and it feeds data to the other.
The problem is, if I delete information from the feeder table, the records are still kept in the storage table.
This is a problem as projects are routinely cancelled and I do not want them clogging up the storage table as if they are useful information.

I currently have the code on my storage table that can delete any rows I want it to delete:
Code:
Sub TestDeleteRows()
Dim rFind As Range
Dim rDelete As Range
Dim strSearch As String


[B][COLOR=#ff0000]strSearch = "YYY" 'I need to tie this to my code below[/COLOR][/B]
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

My problem is, it doesn't do anything as I haven't tied it to the deletion event.
I want my feeder worksheet to prompt the user when they try to delete a row. Once they confirm they are really trying to delete the row, the macro above runs on the storage worksheet.

Here is what I have so far:
Code:
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
[B][COLOR=#ff0000]        ProjectName = YYY  'I am stuck here[/COLOR][/B]




End If
End With
End Sub
 If OnDelete = 0 Then
       Exit Sub
    
    Else

Any help is appreciated. There are many different lines of code out there that don't really do what I want.
I figure I need to use a bunch of If statements.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top