patsdavixen
New Member
- Joined
- Mar 5, 2013
- Messages
- 32
Hi,
I have two sheets in a workbook. The first sheet is named "A" and the second sheet is named "B". Both sheets are identical i.e. they have data ranging from Columns A:AI. However, the number of rows are variable.
I need a macro that will run in loop by looking up data that is mentioned in column D only (the number of rows are variable) on sheet "B" against Column D only in sheet "A". For example, if the word "Popcorn" is mentioned on sheet "B" in cell D2, the macro should look for "Popcorn" in column D in any row in sheet "A". If it finds the word "Popcorn" in sheet A, it should delete the entire row. Once it checks D2 in Sheet "B", it should move on to D3 and so on until it reaches a blank cell (the entire row will also be blank) in column D.
I have the following code but it only searches the cell value of D2. I do not know how to loop it and also have it search only for the range of D
Any help would be greatly appreciated.
Thanks,
Pat
I have two sheets in a workbook. The first sheet is named "A" and the second sheet is named "B". Both sheets are identical i.e. they have data ranging from Columns A:AI. However, the number of rows are variable.
I need a macro that will run in loop by looking up data that is mentioned in column D only (the number of rows are variable) on sheet "B" against Column D only in sheet "A". For example, if the word "Popcorn" is mentioned on sheet "B" in cell D2, the macro should look for "Popcorn" in column D in any row in sheet "A". If it finds the word "Popcorn" in sheet A, it should delete the entire row. Once it checks D2 in Sheet "B", it should move on to D3 and so on until it reaches a blank cell (the entire row will also be blank) in column D.
I have the following code but it only searches the cell value of D2. I do not know how to loop it and also have it search only for the range of D
Code:
Sub Find()
Dim Found As Range
Sheets("A").Select
Set Found = Cells.Find(What:=Sheets("B").Range("D2").Value, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Found Is Nothing Then
MsgBox "Not found", vbInformation
Exit Sub
Else
Found.Select
Selection.EntireRow.Delete
End If
End Sub
Any help would be greatly appreciated.
Thanks,
Pat