So I'm trying to efficiently delete rows in excel spreadsheets that meet a certain criteria. However, I think that it would probably be faster if I could use some built in VBA functionality that would select all the rows that I want to delete, and then delete them all at once.
The following link is the VBA equivalent of something I'd like to do using the python win32com.client module: https://stackoverflow.com/a/31390697/9453718
I am currently just looping through and deleting rows as I go. I go through all the rows in excel, and if it meets some criteria I call: Sheet.Rows(r).EntireRow.Delete()
Any suggestions?
Edit: here's a sample of what I currently have that deletes each row one by one
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
book = excel.Workbooks.Open("ExcelWith200000Lines.xlsm")
sheet = book.Worksheets(0) #gets first sheet
nrows = sheet.UsedRange.Row + sheet.UsedRange.Rows.Count-1 # number of rows
ncols = sheet.UsedRange.Column + sheet.UsedRange.Columns.Count-1 # num of cols
data = sheet.Range('A1:'+NumToLetter(ncols) + str(nrows)).Value #loads all the data on the sheet into the python script
RELEVANT_COL_INDEX=0
for r in range(nrows-1, -1, -1): #starts at last row and goes to first row
if data[r][RELEVANT_COL_INDEX] == "delete_me":
sheet.Rows(r+1).EntireRow.Delete() #deletes the row here
book.SaveAs("myOutput.xlsm")