I am attempting to use Python to insert an empty row at each change, for instance:
Original Workbook:
A
A
A
B
B
C
Outcome:
A
A
A
B
B
C
Code I am working on:
num=2
while num < 13:
if ws['A'+str(num)].value != ws['A'+str(num+1)].value:
ws.insert_rows(num+1)
elif ws['A'+str(num)].value == ws['A'+str(num+1)].value or ws['A'+str(num)].value == '':
pass
num+=1
Output I currently get is
A
A
A
B
B
C
Thanks in advance!
EDIT: SOLVED! In a weird way.
num=2
while num < 13:
if ws['A'+str(num)].value == ws['A'+str(num+1)].value:
pass
elif ws['A'+str(num)].value == ws['J'+str(num)].value:
pass
elif ws['A'+str(num)].value != ws['A'+str(num+1)].value:
ws.insert_rows(num+1)
num+=1
How about to write the code a little bit more tidy. 1st read the input, then find the rows with differences, finally add the rows and save the wb: