Without a script
You may have thousands of words, but it's not practical to have thousands of colors in your spreadsheet, unless you are writing a color vision test. Most people can't reliably tell the difference between subtly different colors, especially on a computer screen. So, if you use a reasonable number of colors (e.g. 50) and group the words on Sheet 2 in 50 columns accordingly, then 50 conditional rules would do the job: each would be a custom formula like
=match(A1, indirect("Sheet2!C1:C"), 0)
where A1 is the upper-left corner of the range to be formatted on Sheet1, and C is one of the word columns on Sheet2.
With a script
If you insist on having thousands of colors, then a script below can do the job. It does the following:
- Runs on every edit
- Checks that the edit is to Sheet1
- Grabs the data from Sheet2
- Looks until either there is a match or the table ends.
- Sets cell background (white if no match).
function onEdit(e) {
if (e.range.getSheet().getSheetName() == 'Sheet1') {
var values = e.source.getSheetByName('Sheet2').getRange('A:B').getValues();
var color = '#ffffff';
var i = 0;
while (i < values.length && values[i][0]) {
if (values[i][0] === e.value) {
color = values[i][1];
break;
}
i++;
}
e.range.setBackground(color);
}
}