Help on deleting rows using Macros
havn't tested this thouroughly but it should work:
Sub Delete_If_Match()
Dim firstRow As Integer, lastRow As Integer
Dim firstRow2 As Integer, lastRow2 As Integer
'WB1 range
firstRow = 1
lastRow = 8
'WB2 range
firstRow2 = 1
lastRow2 = 3
For i = firstRow To lastRow
For j = firstRow2 To lastRow2
If Workbooks("WB1.xls").Worksheets("Sheet1").Cells(i,
1).Value = Workbooks("WB2.xls").Worksheets("Sheet1").Cells(j, 1).Value
Then
Workbooks("WB1.xls").Worksheets("Sheet1").Cells(i,
1).EntireRow.delete
i = i - 1
Exit For
End If
Next j
Next i
End Sub
ashel wrote:
I have two workbooks in the following fashion:
Workbook1/Sheet1 Workbook2/Sheet1
aaa aaa
bbb bbb
ccc
ddd
eee
I want the macro to delete the values in Workbook1/Sheet1/Col1 if they match
with the values ith Workbook2/Sheet1/Col1.
Thanks for your help.
|