Never used Openpyxl and have no advice there, but one way of using loop (with printing out to show result):
>>> cols = list(zip(['B', 'D', 'F', 'H'], ['C', 'E', 'G', 'I'])) >>> for i in range(10, 13): ... for pair in cols: ... print(f'{pair[0]}{i}:{pair[1]}{i}') ... B10:C10 D10:E10 F10:G10 H10:I10 B11:C11 D11:E11 F11:G11 H11:I11 B12:C12 D12:E12 F12:G12 H12:I12In your actual code you should define correct range and replace print row to:
sheet.merge_cells(f'{pair[0]}{i}:{pair[1]}{i}')If you have only 4 pairs then zip is probably overkill, you can write it manually:
cols = [('B', 'C'), ('D', 'E'), ('F', 'G'), ('H', 'I')]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.