First you'll need to initialize two variables, one for holding the number of rows and one for holding the name of the worksheet with the greatest number of rows:
row_count = 0
longest_ws = ""
Then, we need to iterate over all worksheets in the workbook and check their row count using the max_row property. If the row_count is smaller than the current worksheet max_row, update both row_count and longest_ws with appropriate values. Remember that:
- These two variables have to be initialized before the loop.
- The
sheetnames property may come in handy, but it returns a list of worksheet names, not the worksheets themselves.