The currency formats are not updating in the following ranges:
- Expenses💸!C3:C’
- Income 💰!C3:C’
- Transfer 🔄!D3:D’
- Wallets 💵!D3:D’
These ranges are formatted as Google Sheets tables. Other ranges are working properly, except for these table-formatted ranges.
Its showing error
Exception: You can’t set the number format of cells in a typed column.
function updateCurrencyFormat() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var customizationsSheet = ss.getSheetByName('Customizations ❤️');
var currencySymbol = customizationsSheet.getRange('B14').getValue();
// Construct the currency format string using the currency symbol from B14
var currencyFormat = currencySymbol + '#,##0.00_);[Red](' + currencySymbol + '#,##0.00)';
var rangesToUpdate = [
'Computations!D2:H',
'Computations!M3:Q',
'Computations!T2:T',
'Computations!X2:X',
'Dashboard 📈!A11',
'Dashboard 📈!A15',
'Dashboard 📈!A18',
'Dashboard 📈!D18'
];
var dynamicRanges = [
'Dashboard 📈!B23',
'Dashboard 📈!F23',
'Dashboard 📈!N23',
'Dashboard 📈!S23',
'Dashboard 📈!W23',
'Expenses💸!C3:C',
'Income 💰!C3:C',
'Transfer 🔄!D3:D',
'Wallets 💵!D3:D'
];
// Update static ranges
rangesToUpdate.forEach(function(rangeAddress) {
var sheet = ss.getSheetByName(rangeAddress.split('!')[0]);
var range = sheet.getRange(rangeAddress.split('!')[1]);
range.setNumberFormat(currencyFormat);
});
// Update dynamic ranges
dynamicRanges.forEach(function(rangeAddress) {
var sheetName = rangeAddress.split('!')[0];
var startCell = rangeAddress.split('!')[1];
var column = startCell.charAt(0);
var startRow = parseInt(startCell.substring(1));
var sheet = ss.getSheetByName(sheetName);
var lastRow = sheet.getLastRow();
if (lastRow >= startRow) {
var range = sheet.getRange(startRow, column.charCodeAt(0) - 'A'.charCodeAt(0) + 1, lastRow - startRow + 1);
range.setNumberFormat(currencyFormat);
}
});
}
Im trying to change the currency format.
Kenneth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7