Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Trying to color an excel row based on list

The code below uses openpyxl and iterates through all rows and columns in a spreadsheet searching for a value in a list called subID. It then colors each cell it finds with that value light blue. I am trying to figure out how to color the whole row when a cell is found.

Any suggestions on how I can do this? I am not 100% sure but openpyxl may be forcing me to color each cell individually in the row.

#this colors the cell wherever sub id in list is found.

lightblueFill = PatternFill(start_color='c9e1f8',


# iterate over all rows
for ro in range(1,max_row+1):
    # iterate over all columns
    for co in range(1,max_column+1):
        # get particular cell value 
        #searches all cell and columns for a value in a list called subID
        if cell_obj.value in subID:
            #colors the cells found light blue. 
            cell_obj.fill = lightblueFill
I believe this link could help with that type of formatting. Skip to the first example under conditional formatting (the link is in the table of contacts to skip right to it). It shows how to color whole rows based off of an individual cell's value.

Conditional formatting with Python
newbieAuggie2019 and curranjohn46 like this post

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Exporting list with dictionary to Excel veromi22 0 131 Oct-15-2019, 12:54 AM
Last Post: veromi22
  Openpyxl, format color of cells (cols) based on condition. genderbee 0 493 Sep-11-2019, 01:05 PM
Last Post: genderbee
  Create new list from another list based on condition khalidreemy 1 314 Jun-11-2019, 10:21 AM
Last Post: buran
  update values in list based on dictionary bunti 3 837 Jun-10-2019, 07:26 AM
Last Post: perfringo
  splitting numeric list based on condition python_newbie09 7 819 May-27-2019, 03:58 PM
Last Post: python_newbie09
  Get New List Based on Dictionary Key leoahum 4 800 Oct-03-2018, 02:09 PM
Last Post: leoahum
  sorting a list of tuples based on date bluefrog 2 1,385 Aug-10-2018, 02:31 AM
Last Post: ichabod801
  Trying to append List/array based on condition Mr_Keystrokes 1 737 Mar-20-2018, 04:11 PM
Last Post: nilamo
  Is it possible to access and list all macro names in an excel file? kwfine 0 735 Feb-07-2018, 04:21 PM
Last Post: kwfine
  Excel Column as List champk 2 3,530 Jan-03-2018, 11:30 PM
Last Post: karaokelove

Forum Jump:

Users browsing this thread: 1 Guest(s)