Results 1 to 10 of 83

Thread: Delete rows based on match criteria in two excel files or single Excel File

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    conditionally delete or replace entire row

    vba is placed in a seperate files macro.xlsm
    & there are two more files 2.xlsx and 1.xlsx
    all files are located in a different place
    i uploaded the pic of 1.xlsx & 2.xlsx plz look sir
    if column A of 1.xlsx matches with column B of 2.xlsx then keep that entire row of 2.xlsx & if not matches then delete the entire row of 2.xlsx
    in this example 3rd row will be deleted of 2.xlsx
    i need the macro of the same sir
    so plz have a look into this problem and help me in solving this problem sir
    plz see the sample file
    Attached Images Attached Images
    • File Type: png 1.PNG (4.1 KB, 7 views)
    • File Type: png 2.PNG (10.8 KB, 7 views)

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,385
    Rep Power
    10
    Change to this
    Code:
    Dim Rng1A As Range, Rng2B As Range ' , Rng2A As Range
     Set Rng1A = Rng1.Range("A1:A" & Rng1.Rows.Count & ""): Set Rng2B = Rng2.Range("B1:B" & Rng2.Rows.Count & "")  ' : Set Rng2A = Rng2.Range("A1:A" & Rng2.Rows.Count & "")
    Rem 2 take each row in column A of 1.xlsx and compare it with  each row in column B of of 2.xlsx
    Dim Rws As Long
        For Rws = Rng1.Rows.Count To 2 Step -1
            If Rng1A.Item(Rws).Value = Rng2B.Item(Rws).Value Then
            ' Do nothing
            Else
             Rng2B.Item(Rws).EntireRow.Delete Shift:=xlUp
            End If
        Next Rws
    End Sub
    Before:-
    _____ Workbook: 1.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    1
    2
    ACC
    6
    3
    DLF
    4
    4
    Worksheet: Sheet1

    _____ Workbook: 2.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    1
    Exchange
    2
    NSE ACC EQ
    10
    11
    12
    13
    3
    NSE ADANIENT EQ
    8
    7
    6
    5
    4
    NSE DLF EQ
    1
    2
    3
    4
    5
    Worksheet: Sheet1


    After:

    _____ Workbook: 1.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    1
    2
    ACC
    6
    3
    DLF
    4
    4
    Worksheet: Sheet1

    _____ Workbook: 2.xlsx ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    Exchange
    2
    NSE ACC EQ
    10
    11
    12
    3
    NSE DLF EQ
    1
    2
    3
    4
    5
    Worksheet: Sheet1
    Last edited by DocAElstein; 03-23-2020 at 04:56 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Replies: 29
    Last Post: 06-09-2020, 06:00 PM
  2. Replies: 3
    Last Post: 10-20-2015, 12:51 PM
  3. VBA To Delete Rows Based On Value Criteria In A Column
    By jffryjsphbyn in forum Excel Help
    Replies: 1
    Last Post: 08-15-2013, 12:45 PM
  4. Replies: 6
    Last Post: 08-14-2013, 04:25 PM
  5. Delete Remove Rows By Criteria VBA Excel
    By marreco in forum Excel Help
    Replies: 5
    Last Post: 12-20-2012, 05:56 PM

Tags for this Thread

Posting Permissions

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