Google Sheets – How to Use Cell Reference with Color Formatting

formattinggoogle sheetsgoogle-apps-script

Is it possible to reference a cell in Google Sheets so that cell where it gets displayed also displays it using the same text and cell colour formatting?

=A1

Will only reference cell's value. But if that particular cell has red background and white text I'd like that to be copied as well.

I'm leaning toward existing formula solutions rather than scripts. If applicable of course.

Best Answer

For Google Spreadsheets, it is possible by writing a script:

function copyValuesAndFormatting() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet();

    var fromRange = sheet.getRange("A2:A");
    var toRange = sheet.getRange("B2:B");
    var values = fromRange.getValues();
    var fontColors = fromRange.getFontColors();
    var backgrounds = fromRange.getBackgrounds();
    var fonts = fromRange.getFontFamilies();
    var fontWeights = fromRange.getFontWeights();
    var fontStyles = fromRange.getFontStyles();

    toRange.setBackgrounds(backgrounds);
    toRange.setFontColors(fontColors);
    toRange.setValues(values);
    toRange.setFontFamilies(fonts);
    toRange.setFontWeights(fontWeights);
    toRange.setFontStyles(fontStyles);
}

Add a trigger for the script function, so that it runs on every spreadsheet modification.

I have created a sample spreadsheet here. Feel free to copy it to your own account, and start experimenting with it.