Excel Delete from column A - delete from all other worksheets

If I have data in column A of the "master" sheet and I delete it, I want to be able to delete the related data in all worksheets in the workbook.  The other worksheets would have the data in column A (matching what what is column A of the master).  I need to delete column A and B in the other sheets.  I don't want to delete the whole row, just the data.

How can I do this with VBA?

See attached file.  Please update attached with your code.
DELETE-EXAMPLE2.xlsx
maverick0728Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I'm assuming this is what you are looking for..this code will go into sheet module of master..

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("A:A")) Is Nothing Then Exit Sub
deletedata

End Sub

Open in new window


And this will go into new module...

Sub deletedata()
    Dim ws As Worksheet, rng As Range, cell As Range, r As Range
    Dim lrow As Long, lrow1 As Long, r1 As Range
    Dim ws1 As Worksheet

    Set ws1 = Sheets("MASTER")

    lrow = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    Set rng = Range("A2:A" & lrow)


    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> ws1.Name Then
            lrow1 = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
            Set r = ws.Range("A2:A" & lrow1)

            For Each cell In r

                If Application.WorksheetFunction.CountIf(rng, cell.Value) = 0 Then

                    If r1 Is Nothing Then
                        Set r1 = cell
                    Else
                        Set r1 = Union(r1, cell)
                    End If


                End If

            Next cell

            If Not r1 Is Nothing Then r1.EntireRow.Delete
            Set r1 = Nothing


        End If

    Next ws

End Sub

Open in new window


Enclosed is working example for your reference.. what this will do as soon you delete a value in A Column of master that row will be deleted from all your worksheets..automatically...

Saurabh...
DELETE-EXAMPLE2.xlsm
0
maverick0728Author Commented:
I am getting strange results when my data doesn't always start in row 2.  Sometimes the headers are deleted.  See the example attached.
DELETE-EXAMPLE3.xlsm
0
Saurabh Singh TeotiaCommented:
So if i understand correctly you are saying for each worksheet data or header rows not necessarily at row-2?? If that's the case can you help me understand the logic why do you move headers?? And can i use headers value like item or static as value to find header row??
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

maverick0728Author Commented:
Each worksheet may be different with a starting point for the headers.  This is for an estimate.  Each worksheet is for a specific workcenter and there are some reference values in the top rows for each worksheet.  Most start at row 2, 5 or row 22, but it can be dynamic.  
You can use the value "item" to find the header row.
Thanks for your help.
0
Saurabh Singh TeotiaCommented:
Their you go enclosed your workbook for your reference where i did the necessary changes...

Saurabh...
DELETE-EXAMPLE3-1.xlsm
0
maverick0728Author Commented:
This looks like its working, the issue though is that we don't want to delete the entire row.  How can I just delete the data in column A and B on the other sheets?
0
Saurabh Singh TeotiaCommented:
Quick question when you say delete you want to delete cells A and B and move the cell which are below to up or you just want to clear the A and B Cell?? Which one you want to do??
0
maverick0728Author Commented:
just clear the A and B cell
0
Saurabh Singh TeotiaCommented:
Use this version...

Saurabh...
DELETE-EXAMPLE3-1.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maverick0728Author Commented:
It works perfectly.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.