Delete Specific rows in Excel -
I want to check all the rows in a sheet for the loop which I have and this code should be enabled If they contain a specific content in certain columns (i.e. if the "June" line in column Kashmir is removed for removal), is there any way to code this?
* Edit Find the code to work in a column's criteria, but now let me know It is necessary to search and delete rows based on data in two columns, that is, if the data in the column matches the AJ1 (already exists) and the data in column J is equal to A1, then these rows .
The code I got is:
Delete sub ()
sheet ("sheet 1"). (": Kashmir K ") set rFind range dim strSearch string as slow iLookAt (" AJ1 ") as long as dim bMatchCase boolean strSearch = range iLookAt = xlWho Le bMatchCase = false set = rDelete = nothing with Application.ScreenUpdating Sheet1.Columns = as false = Find (strings search, Lookin: = XLVivalues, Look at: = ArchuAtt, ArchDirection: = xlPrevious, MatchCase: = bMatchCase) No rFind, then set rDelete = rFind set rFind = .FindPrevious (rFind) if rFind Address = rDelete.Address then set rFind = nothing is not rDelete.EntireRow.Delete loop while not ending if the RFIDD does not end something if the application ends with. ScreenUpdating = True Termination sub
A common rule of thumb As such, if possible, looping on cells in Excel VBA should be avoided. Looping on the cells does not make any difference to the scope of your program, but it should be considered something. If you are new to VBA programming, it is especially important to start good habits.
Here is a solution by using the Range.Find method to delete), and then delete them all in one statement. Sub DeleteRows () As the RangeResults Range, the RangeToDelete as Range Dims strFirstAddress worksheets as String ("Sheet1"). Adjust 'with UsedRange' to set your special worksheet to set rngResults = .Cells.Find (what: = "June") 'Adjust if you do not want to find it, then rngResults is nothing (set) RngToDelete = rngResults strFirstAddress = rngResults.Address set rngResults = .FindNext after: = RngResults) rngResults.Address = strFirstAddress set rngToDelete = Application.Union (rngToDelete, rngResults) set rngResults = .FindNext (after: = rngResults) loop termination If not ending with rngToDelete, then rngToDelete.EntireRow.Delete set rngResults = nothing ending sub
Comments
Post a Comment