0

I did go through some posts here to remove duplicates from list of files in folder using Python openpyxl.
Did not find suitable one to my needs.
Here is the script which I have and want to modify below script which can loop through list of files in a folder to remove duplicates rows by column.
It would be better If I get popup box to mention Column Name like by ColumnA, because every time I have to change by column Name to remove duplicates on list of files.

Here is the code which I have.

import openpyxl
wb = openpyxl.load_workbook('Duplicates.xlsx')
wb2 = openpyxl.load_workbook('Duplicates.xlsx')
sh = wb['Sheet1']
sh2 = wb2['Sheet1']

values = []

for i in range(1, sh.max_row + 1):
    a = sh.cell(row=i, column=1).value
    if a in values:
        pass
    else:
        values.append(sh.cell(row=i, column=1).value)

for x in range(len(values)):
    sh2.cell(row=x + 1, column=1).value = values[x]

wb2.save('new_file.xlsx')
TheEagle
  • 5,808
  • 3
  • 11
  • 39
kumar
  • 1
  • 2
  • Please format the code (select it and type `ctrl-k`) and fix the indentation. [Formatting help](https://stackoverflow.com/editing-help)... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii Feb 07 '21 at 14:23
  • Thanks and I updated script. – kumar Feb 12 '21 at 19:43
  • can anyone help me? I been doing it manually. Taking countless hours. – kumar Feb 15 '21 at 11:49

0 Answers0