我无法清除并重置单元格的背景颜色 [英] I am not able to clear and reset the background color of a Cell
问题描述
借助下面的命令,我可以清除单元格的内容,而不是它们的背景颜色。如何清除并设置范围内的单元格的背景颜色?
With the help of the below command I am able to clear the contents of the cells but not their background color. How to clear and set the background color of cells in a range?
ob9.Range(ob9.Cells(1,StartCol),ob9.Cells(1,maxcolumn)).ClearContents
em>
我尝试了以下:
CountFill = objExcel1.Application.WorksheetFunction.CountA(ob9.Rows(1))
CountBlnk = objExcel1.Application.WorksheetFunction.CountBlank(ob9.Rows(1))
TotalColumn= CountBlnk + CountFill
ob9.Range(ob9.Cells(1,CountFill + 1 ),ob9.Cells(1,TotalColumn)).Interior.ColorIndex(-4142) '= xlColorIndexNone
可以单行完成吗?
谢谢
推荐答案
一切都很好。但是不要选择,因为您正在运行一个巨大的脚本(知道你到目前为止已经完成了什么)...
Everything is fine. But don't select given you are running a huge script (knowing what you went through so far)...
with ob9.Range(ob9.Cells(1,StartCol),ob9.Cells(1,maxcolumn))
.Interior.ColorIndex = xlColorIndexNone
.Interior.ColorIndex = 120
End With
如果您直接使用范围
你甚至可以删除块的,因为它也有一些性能降低的缺点。
If you are directly using the range
you may even remove with
block, as it too has some performance-slowing drawback.
- Reference article
您的子问题的答案:
-
如何从列号获取列名?
How to get column name from column number?
如何根据OP的 maxcolumn
名称或号码设置范围。
How to set range based on the OP's maxcolumn
name or number.
你提到你需要行1
, maxcolumn
然后你可以使用这两个数据构建单元格。
You mentioned you need row 1
, maxcolumn
then you can build the cell using those two data.
MsgBox Sheets(3).Rows(1).Columns(5).Address
所以尝试一下:
MsgBox Sheets(3)。行(1).Columns(maxcolumn).Address
这篇关于我无法清除并重置单元格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!