|
function test()
{
let rg = Sheets.Item('Sheet1').Range('e8:g8')
//先在目标区域填充公式以更新目标文本(用宏本身的数据处理方法也行,这里是懒得写了)
rg.Formula2 = ['=TEXTJOIN(CHAR(10),,FILTER(LOOKUP(COLUMN($H:$P),IF($H$1:$P$1<>"",COLUMN($H:$P),""),$H$1:$P$1)&":"&CHAR(10)&$H3:$P3,($H$2:$P$2=E$2)*($H3:$P3<>"")))'
, '=TEXTJOIN(CHAR(10),,FILTER(LOOKUP(COLUMN($H:$P),IF($H$1:$P$1<>"",COLUMN($H:$P),""),$H$1:$P$1)&":"&CHAR(10)&$H3:$P3,($H$2:$P$2=F$2)*($H3:$P3<>"")))'
, '=TEXTJOIN(CHAR(10),,FILTER(LOOKUP(COLUMN($H:$P),IF($H$1:$P$1<>"",COLUMN($H:$P),""),$H$1:$P$1)&":"&CHAR(10)&$H3:$P3,($H$2:$P$2=G$2)*($H3:$P3<>"")))'];
//目标区域转文本
rg.Value2 = rg.Value2;
//重置目标区域字体颜色为黑色
rg.Font.Color = 0
//对目标区域字体颜色进行循环调色
for(cell of rg){
[Range('h1'), Range('k1'), Range('n1')].forEach(c => {
let text = c.Text, s = cell.Text.indexOf(text), l = text.length;
cell.Characters(s + 1, l).Font.Color = c.Font.Color
})
}
} |
|