+ Reply to Thread
Results 1 to 4 of 4

Ignore Blank Cells in Custom Conditional Formatting

  1. #1
    Registered User
    Join Date
    04-11-2024
    Location
    Baltimore, MD
    MS-Off Ver
    Office 365
    Posts
    3

    Exclamation Ignore Blank Cells in Custom Conditional Formatting

    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();
    }
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,924

    Re: Ignore Blank Cells in Custom Conditional Formatting

    Does this work for you? It needed a "stop if true" put after the blank cell assessment.

    PHP Code: 
    function main(workbookExcelScript.Workbook) {
        const 
    sheet workbook.getWorksheet("Secondary");
        const 
    dataRange sheet.getRange("A1:J1000");
        const 
    sheet2 workbook.getWorksheet("Primary");
        const 
    dataRange2 sheet2.getRange("A1:J1000");
        
    let blankCellsExcelScript.ConditionalFormat;
        
    let rangeValues dataRange.getValues();
        
    sheet.activate();

        
    dataRange.clearAllConditionalFormats();

        
    blankCells =
            
    dataRange.addConditionalFormat(ExcelScript.ConditionalFormatType.cellValue);
            
            
        
    let ruleExcelScript.ConditionalCellValueRule = {
            
    formula1"0",
            
    operatorExcelScript.ConditionalCellValueOperator.equalTo
        
    };
        
    blankCells.getCellValue().setRule(rule);
        
    blankCells.setStopIfTrue(true);

        
    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);

    Last edited by ByteMarks; 04-11-2024 at 11:33 AM.

  3. #3
    Registered User
    Join Date
    04-11-2024
    Location
    Baltimore, MD
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Ignore Blank Cells in Custom Conditional Formatting

    That worked perfectly! Thank you!

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,924

    Re: Ignore Blank Cells in Custom Conditional Formatting

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Make conditional formatting ignore blank cells
    By theedonjoe in forum Excel General
    Replies: 2
    Last Post: 01-06-2019, 08:13 AM
  2. [SOLVED] Make conditional formatting ignore blank cells
    By HarryMcLean in forum Excel General
    Replies: 5
    Last Post: 05-18-2017, 08:52 AM
  3. [SOLVED] How To Ignore Blank Cells with Conditional Formatting
    By gloriousglenn in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-16-2015, 12:03 PM
  4. Conditional Formatting to ignore blank cells 2003
    By colonelkaye in forum Excel General
    Replies: 1
    Last Post: 07-12-2015, 02:34 PM
  5. Conditional Formatting - ignore Blank Cells
    By therealtfloss in forum Excel General
    Replies: 1
    Last Post: 02-09-2015, 11:38 AM
  6. [SOLVED] How to get Conditional Formatting to ignore blank cells?
    By AndyHawke in forum Excel General
    Replies: 3
    Last Post: 08-22-2012, 08:25 AM
  7. How to ignore blank cells in conditional formatting?
    By Gooford in forum Excel General
    Replies: 5
    Last Post: 08-22-2012, 08:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1