admin管理员组文章数量:1305571
I used this post as a template for creating multiple conditional formats, however, I am also trying to include a loop function for Range H5:XX5 to start at H5, check the cell if it matches a month (as a number 1-12), highlight cell accordingly, then move five columns to the right through Cell XX5. Once we figure this out, I can likely figure out how to complete a second set of Cond Formatting on Row 6, below my dates, using the helper cells highlighted in yellow. See Image Here
Template code: Excel OfficeScript with multiple conditional formatting rules
My code below is not quite working yet, likely due to the Month formula. I was able to successfully get it working following the 1st Answer, but not the 2nd Answer, and also not with a loop. Looking for assistance to add in a loop, as described above.
function main(workbook: ExcelScript.Workbook) {
// Get the range to format.
const shAttendance = workbook.getWorksheet("Drew's Workload");
const rngAttendanceData = shAttendance.getRange("H5:XX5");
let condFormat: object[] = [
["=Month(H5)=1", "Blue"],
["=Month(H5)=2", "Yellow"],
["=Month(H5)=3", "#9C5701"],
["=Month(H5)=4", "#9C5702"],
["=Month(H5)=5", "#9C5703"],
["=Month(H5)=6", "#9C5704"],
["=Month(H5)=7", "#9C5705"],
]
for (let cFormat of condFormat) {
let conditionalFormat = rngAttendanceData.addConditionalFormat(
ExcelScript.ConditionalFormatType.cellValue).getCellValue();
let rule: ExcelScript.ConditionalCellValueRule = {
formula1: cFormat[0],
operator: ExcelScript.ConditionalCellValueOperator.equalTo
};
conditionalFormat.setRule(rule);
let format = conditionalFormat.getFormat();
format.getFill().setColor(cFormat[1]);
}
}
本文标签: Excel OfficeScript with multiple conditional formatting rules AND Loop through ColumnsStack Overflow
版权声明:本文标题:Excel OfficeScript with multiple conditional formatting rules AND Loop through Columns - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741805178a2398458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论