I've got code to color columns A-I a certain color based on a word in a column G. i want to sort by color and to do that i think i have to sort by the color index number so i was able to get a custom function code to tell me the color index of a cell in the different rows, I put the formula of =backgroundcolor(G3) in column J which tells me the nubmer. The problem is when I want to go change the word in column G the color doesn't change according to the new word...... Can anyone help debug this?

copybook2.xls