Code:
Sub conditionally_delete()
On Error Resume Next
Dim Wb1 As Workbook, Wb2 As Workbook, Ws1 As Worksheet, Ws2 As Worksheet
Set Wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\Upstox\STEP1U.xlsb")
Set Ws1 = Wb1.Worksheets.Item("Sheet1") ' worksheet with string tab name of Sheet1
Set Wb2 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\1.xls")
Set Ws2 = Wb2.Worksheets.Item(1) ' worksheet of first tab
'1b Ranges
Dim Rng1A As Range, Rng2B 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
Wb1.Save
Wb1.Close
Wb2.Save
Wb2.Close
End Sub
I am getting error with this line Doc Sir
Code:
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 & "")
plz have a relook Doc Sir
Bookmarks