Consulting

Results 1 to 3 of 3

Thread: Solved: if find data delete the row on another sheet

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Exclamation Solved: if find data delete the row on another sheet

    I have a some data on sheet 1 column A and also some data on sheet 2.
    Now I need a VBA code if have the same data on sheet 2 delete the row on sheet 2 of that data .

    Note : just check with sheet 1 column A .

    Thank you very much for your big help .
    Attached Files Attached Files

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    so you're comparing column A's of Sheet1 & Sheet2, and deleting the matching rows from Sheet2...

    if this is the scenario then try :

    [VBA]
    Sub DelMatchedRows()

    Dim LastRow As Long, i As Long, mRow As Long

    With Worksheets("Sheet1")
    LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    For i = 1 To LastRow
    On Error Resume Next
    mRow = Application.Match(.Cells(i, 1), Worksheets("Sheet2").Columns(1), 0)
    If mRow > 0 Then Worksheets("Sheet2").Rows(mRow).EntireRow.Delete
    Next
    End With

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    That’s correct and thank you so much .
    Last edited by parscon; 08-14-2012 at 04:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •