Delete entire row

agog12

Board Regular
Joined
Jan 23, 2018
Messages
104
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
 

Attachments

  • 1.PNG
    1.PNG
    3.8 KB · Views: 5
  • 2.PNG
    2.PNG
    10.6 KB · Views: 5

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Assuming ..
- All 3 files are open
- The data you have shown is on a sheet called 'Sheet1' in those two workbooks

.. then try this. (Make sure you have backups of your files first)

VBA Code:
Sub DelUnwantedRows()
  With Workbooks("2.xlsx").Sheets("Sheet1")
    .Range("Z2").Formula = "=ISNA(MATCH(B2,[1.xlsx]Sheet1!A:A,0))"
    With .Range("A1").CurrentRegion
      .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=.Range("Z1:Z2"), Unique:=False
      .Offset(1).EntireRow.Delete
    End With
    On Error Resume Next
    .ShowAllData
    On Error GoTo 0
    .Range("Z2").ClearContents
  End With
End Sub
 
Upvote 0
Sorry Sir my files are not opened
so i need according to that condition sir
So, add some code at the beginning of the macro to open them? (& close them again at the end if you want)

I cannot give you the code for that because I do not know the location of the files but you should be able to turn on the macro recorder and open the files. Then you will have some code to work with.
 
Upvote 0
You're welcome. Glad you were able to finish it off. :)
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

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