I have file file name is macro1.xlsm
i have a second file file name is 1.xls
i will add the macro in macro.xlsm
my first row contains headers in 1.xls file
If column D of 1.xls file matches with column H of 1.xls file then delete that complete row and save the changes and close the file
This is my problem
plz see the problem and code and let me know does my vba code contains error
i have a second file file name is 1.xls
i will add the macro in macro.xlsm
my first row contains headers in 1.xls file
If column D of 1.xls file matches with column H of 1.xls file then delete that complete row and save the changes and close the file
This is my problem
Code:
Sub Del()
Dim wbk1 As Workbook
Dim wsh1 As Worksheet
Dim rg As Range
Dim i As Long
Application.ScreenUpdating = False
Set wbk1 = Workbooks.Open(ThisWorkbook.Path & "\1.xls")
Set wsh1 = wbk1.Worksheets(1)
Set rg = wsh1.Range(wsh1.Cells(wsh1.Rows.Count, "D").End(xlUp), wsh1.Cells(2, "D"))
For i = rg.Cells.Count To 1 Step -1
If rg(i).Value = rg(i).Offset(0, 4).Value Then rg(i).EntireRow.Delete
Next i
Application.DisplayAlerts = False
wbk1.Close SaveChanges:=True
Application.DisplayAlerts = True
End Sub
plz see the problem and code and let me know does my vba code contains error