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
[TABLE="width: 283"]
<tbody>[TR]
[TD]NAME[/TD]
[TD]ADDRESS[/TD]
[TD] AGE[/TD]
[TD] COMPANY[/TD]
[TD]POSITION[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]XYZ[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD]DDD[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]GASDD[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]XYZ[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[/TR]
</tbody>[/TABLE]
in "Need to be removed" sheet
[TABLE="width: 50"]
<tbody>[TR]
[TD]NAME[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[/TR]
[TR]
[TD]DDD[/TD]
[/TR]
[TR]
[TD]XYZ
[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 283"]
<tbody>[TR]
[TD]NAME[/TD]
[TD]ADDRESS[/TD]
[TD] AGE[/TD]
[TD] COMPANY[/TD]
[TD]POSITION[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]XYZ[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD]DDD[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]GASDD[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]XYZ[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[/TR]
</tbody>[/TABLE]
in "Need to be removed" sheet
[TABLE="width: 50"]
<tbody>[TR]
[TD]NAME[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[/TR]
[TR]
[TD]DDD[/TD]
[/TR]
[TR]
[TD]XYZ
[/TD]
[/TR]
</tbody>[/TABLE]
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