Tengo una lista cambiante de números en una pestaña a la que me gustaría aplicar formato condicional, si la celda está presente en otra lista de números, en una hoja diferente.
Ciudades Potenciales/Códigos Postales
Lista de códigos postales bloqueados
Me gustaría que los códigos postales en la hoja principal de "Ciudades potenciales" tengan formato cuando aparecen en la hoja "Códigos postales bloqueados".
El propósito es crear un cambio de formato que muestre claramente al usuario si un código postal que intenta ingresar está bloqueado (o en la lista). El formato condicional normal no funciona porque copiar/pegar sobrescribirá las reglas de CF. También necesito poder aplicar la solución a varias hojas diferentes, que están comparando sus celdas con la lista de celdas bloqueadas.
Puede crear un onEdit() para su hoja de cálculo de ciudades potenciales que verifica la hoja de cremalleras bloqueadas en busca de una coincidencia y aplica algún tipo de formato en consecuencia.
function checkForBlockedZips(e) { // do nothing if not column D if (e.range.getColumn() !== 4) return // get list of zips from blocked zips sheet const blockedZipsSsId = "your-spreadsheet-id" const blockedZipsSs = SpreadsheetApp.openById(blockedZipsSsId) const blockedZipsSheet = blockedZipsSs.getSheetByName("Sheet1") const zipCodes = blockedZipsSheet.getRange("A2:A").getValues() .flat(2) .filter(x => x) // check if the entered value is in the list of blocked zips if (~zipCodes.indexOf(e.range.getValue())) { // create cell style const strikethrough = SpreadsheetApp.newTextStyle() .setStrikethrough(true) .build() const richText = SpreadsheetApp.newRichTextValue() .setText(e.range.getValue()) .setTextStyle(strikethrough) .build() // set the cell to have the desired rich text style e.range.setRichTextValue(richText).setBackground("yellow") } else { // if the value is not a blocked zip then reset the cell style const nostrikethrough = SpreadsheetApp.newTextStyle() .setStrikethrough(false) .build() const richText = SpreadsheetApp.newRichTextValue() .setText(e.range.getValue()) .setTextStyle(nostrikethrough) .build() e.range.setRichTextValue(richText).setBackground("white") } }Cosas a tener en cuenta:
e.range.getValue() en lugar de e.value para que se puedan leer los valores copiados/pegados