the way you did it you don't need the first 2 lines. However better do
for row in (1, 4): sheet.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9) columns = [(col, col+1) for col in range(2, 9, 2)] for row in [2, 3, 5, 8, 11, 12, 13, 17, 18, 23, 25, 29, 30, 31, 32, 40, 101]: for col1, col2 in columns: sheet.merge_cells(start_row=row, start_column=col1, end_row=row, end_column=col2) for row in (1, 4): sheet.merge_cells(start_row=row, start_column=2, end_row=row, end_column=3) sheet.merge_cells(start_row=row, start_column=6, end_row=row, end_column=9)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs