Skip to content
Advertisement

How to copy without empty cells from sheet A to sheet B?

I have tried everything but not being successful, this is my code to copy from sheet A to sheet B, I don’t know what to add to make it work:

for row in range(6, 136):
    c = ws.cell(row=row, column=2)
    ws2.cell(row=row-1, column=2, values=c.value)

Advertisement

Answer

n = 5 #row to star writing
for row in range(6,137):
    c = ws.cell(row = row, column = 2)

    if c.value is not None:
        ws2.cell(row = n, column = 2 , value = c.value)
        n += 1 #increment to write skiping blank cells
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement