keilah
08-06-2007, 12:54 AM
Hi Everyone
I have the follwing VBA, i need to match two worksheet and delete items (rows) in work sheet 2 that DO NOT match with worksheet 1 "must be and exact match" - then delete unmatched - rows
And also i want to say which two col'n i want to match in the spreadsheet.
I will attched the excel spread sheet for you to look at.
Any questio, message me back......
here is the vab code:
Sub DeleteunmatchedData()
Do
Col1 = Application.InputBox("Please enter column for sheet 1")
If Col1 = False Then: Exit Sub
Loop Until IsNumeric(Col1) And Col1 <> vbNullString
Do
Col2 = Application.InputBox("Please enter 2nd column for sheet 2")
If Col2 = False Then: Exit Sub
Loop Until IsNumeric(Col1) And Col1 <> vbNullString
For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Sheets(1).Cells(r, Col1).Value <> Sheets(2).Cells(r, Col2).Value Then
Sheets(2).Cells(r, Col2).EnitreRow.Delete
End If
Next r
End Sub
I have the follwing VBA, i need to match two worksheet and delete items (rows) in work sheet 2 that DO NOT match with worksheet 1 "must be and exact match" - then delete unmatched - rows
And also i want to say which two col'n i want to match in the spreadsheet.
I will attched the excel spread sheet for you to look at.
Any questio, message me back......
here is the vab code:
Sub DeleteunmatchedData()
Do
Col1 = Application.InputBox("Please enter column for sheet 1")
If Col1 = False Then: Exit Sub
Loop Until IsNumeric(Col1) And Col1 <> vbNullString
Do
Col2 = Application.InputBox("Please enter 2nd column for sheet 2")
If Col2 = False Then: Exit Sub
Loop Until IsNumeric(Col1) And Col1 <> vbNullString
For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Sheets(1).Cells(r, Col1).Value <> Sheets(2).Cells(r, Col2).Value Then
Sheets(2).Cells(r, Col2).EnitreRow.Delete
End If
Next r
End Sub