m_vishal_c
Board Regular
- Joined
- Dec 7, 2016
- Messages
- 209
- Office Version
- 365
- 2016
- Platform
- Windows
hi I have 2 sheets(Sheet1, Need to be removed) in Excel workbook. i need to remove all rows from Sheet1 where column name contains list from sheet "Need to be removed".
for that i am using below code but it does not delete all rows.
for example. in Sheet1, there are 10 rows of Person name "abc" when i run this code it does not delete all 10 rows. I got these below code from internet and i am new to macro. Please help me.
Please guide me. much appreciate your time and support
for that i am using below code but it does not delete all rows.
for example. in Sheet1, there are 10 rows of Person name "abc" when i run this code it does not delete all 10 rows. I got these below code from internet and i am new to macro. Please help 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).Delete xlShiftUp
' 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 time and support