m_vishal_c
Board Regular
- Joined
- Dec 7, 2016
- Messages
- 209
- Office Version
- 365
- 2016
- Platform
- Windows
HI i have two sheet in one workbook, " Sheet1" and " Need to be removed ". i need to remove all data from sheet1 from matching "Need to be removed " sheet column.
For example in Sheet1
<tbody>
</tbody>
in "Need to be removed" sheet
<tbody>
</tbody>
I need to remove all rows from Sheet 1 where name=abc from "Need to be removed" list.
for that i am using below code but it does not remove all rows. Please guide me
Please guide me. much appreciate your support and time
thanks
For example in Sheet1
NAME | ADDRESS | AGE | COMPANY | POSITION |
ABC | 1 | 1 | 1 | 1 |
XYZ | 2 | 1 | 2 | 1 |
ABC | 3 | 11 | 3 | 11 |
DDD | 4 | 1 | 4 | 1 |
GASDD | 4 | 1 | 4 | 1 |
XYZ | 5 | 1 | 5 | 1 |
<tbody>
</tbody>
in "Need to be removed" sheet
NAME |
ABC |
DDD |
XYZ |
<tbody>
</tbody>
I need to remove all rows from Sheet 1 where name=abc from "Need to be removed" list.
for that i am using below code but it does not remove all rows. Please guide me
Code:
Dim iListCount As IntegerDim iCtr As Integer
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False
' Get count of records to search through (list that will be deleted).
iListCount = Sheets("Sheet1").Range("A1:A5000").Rows.Count
' Loop through the "master" list.
For Each x In Sheets("Need to be removed").Range("A2:A30")
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets("Sheet1").Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets("Sheet1").Cells(iCtr, 1).[COLOR=#333333]EntireRow.Delete xlShiftUp[/COLOR]
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
Please guide me. much appreciate your support and time
thanks