I'm trying to write a very simple script that will compare data between two worksheets and highlight differences between the two. However, these sheets are both regularly updated and will often have incomplete data comparisons. Rather than highlight these blank cells as errors, I would prefer if they were ignored by my code. I have tried inserting separate rules that apply to zero-value cells and blank cells, but the main conditional formatting continues to override them and will highlight blank cells. I am not sure how to change the formatting itself so that it ignores blank cells.
I should also note that any solutions must be ONLY IN OFFICE SCRIPTS. I CANNOT USE VBA due to institutional limitations on my Office subscription capabilities. This data is collectively edited and will only be accessed via the web version of Excel.
Here is my code as it stands: "TEST"
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getWorksheet("Secondary");
const dataRange = sheet.getRange("A1:J1000");
const sheet2 = workbook.getWorksheet("Primary");
const dataRange2 = sheet2.getRange("A1:J1000");
let rangeValues = dataRange.getValues();
sheet.activate();
dataRange.clearAllConditionalFormats();
const blankCells =
dataRange.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue).getCellValue();
let rule: ExcelScript.ConditionalCellValueRule = {
formula1: "0",
operator: ExcelScript.ConditionalCellValueOperator.equalTo
};
blankCells.setRule(rule);
sheet.activate();
const valueConflict = dataRange.addConditionalFormat(ExcelScript.ConditionalFormatType.custom).getCustom();
valueConflict.getFormat().getFill().setColor("#F8696B");
valueConflict.getRule().setFormula(
`=${dataRange.getAddress()}<>${dataRange2.getAddress()}`
)
const format = dataRange.getFormat();
format.getRangeBorder(ExcelScript.BorderIndex.edgeTop);
format.getRangeBorder(ExcelScript.BorderIndex.edgeBottom);
format.getRangeBorder(ExcelScript.BorderIndex.edgeLeft);
format.getRangeBorder(ExcelScript.BorderIndex.edgeRight);
blankCells.getFormat().getFill().clear();
}
Bookmarks