提问人:cheese10234 提问时间:9/5/2023 更新时间:9/5/2023 访问量:44
为什么检查单元格背景颜色的 If 函数不起作用?
Why is my If function that is checking the background color of a cell not working?
问:
首先,代码:
If ws.Cells(.Value + 1, 28).Interior.ColorIndex = 16 Then Mark1.LU1DISCOCHECK = True Else Mark1.LU1DISCOCHECK = False
单元格是正确的颜色,但 if 语句根本没有更改复选框。 我对颜色索引不太熟悉,但据我所知,这应该可以正常工作。
我错过了什么吗?
答:
2赞
Matheus
9/5/2023
#1
尝试:
如果 ws.单元格(.值 + 1, 28)。DisplayFormat.Interior.Color = RGB(250, 200, 150) 那么 mark1.LU1DISCOCHECK = true else mark1.LU1DISCOCHECK = false
艺术
如果 ws.单元格(.值 + 1, 28)。DisplayFormat.Interior.ColorIndex = 16 那么 mark1.LU1DISCOCHECK = true else mark1.LU1DISCOCHECK = false
1赞
Tim Williams
9/5/2023
#2
像这样更容易:
Mark1.LU1DISCOCHECK = (ws.Cells(.Value + 1, 28).DisplayFormat.Interior.ColorIndex = 16)
评论
DisplayFormat.Interior.ColorIndex
If Mark1.LU1DISCOCHECK = True Then ws.Cells(.Value + 1, 28).Interior.ColorIndex = 16 Else ws.Cells(.Value + 1, 28).Interior.ColorIndex = 2