[英]VBA - retrieving cell colours for all cells in a range all at once
I'm working on an optimization task for our data reconciliation workbook and part of the work the code does is to colour certain cells a specific color based on some conditions. 我正在为数据对帐工作簿进行优化任务,该代码所做的部分工作是根据某些条件为某些单元格着色为特定的颜色。 I would like to retrieve all cell colours in a 2D array similarly to how you can retrieve all cell values in a range using: 我想在2D数组中检索所有像元颜色,类似于如何使用以下方法检索范围中的所有像元值:
Dim myRangeVals() as Variant
myRangeVals = someRange.value
I tried using the following code but Interior.Color
returns a Double
: 我尝试使用以下代码,但是Interior.Color
返回Double
:
Dim myCellColours() as Variant
myCellColours = someRange.Interior.Color
Is there a way to retrieve all cell colours all at once(without looping of course)? 有没有办法一次检索所有单元格颜色(当然不循环)?
Thanks 谢谢
Is there a way to retrieve all cell colours all at once(without looping of course)? 有没有办法一次检索所有单元格颜色(当然不循环)?
No, it is not. 不它不是。
Have a look at Range Object (Excel) . 看一下Range Object(Excel) 。
There you will find Range.Value Property (Excel) which has a property RangeValueDataType
which is xlRangeValueDefault by default. 在那里,您将找到Range.Value属性(Excel) ,该属性具有属性RangeValueDataType
,默认情况下为xlRangeValueDefault 。 And this means: 这意味着:
...If the Range object contains more than one cell, returns an array of values... ...如果Range对象包含多个单元格,则返回值数组...
Thats why the Range.Value
may be returning an array. 这就是为什么Range.Value
可能返回数组的原因。
But Range.Interior Property (Excel) : 但是Range.Interior Property(Excel) :
Returns an Interior object that represents the interior of the specified object. 返回一个内部对象,该对象表示指定对象的内部。
This means one Interior Object (Excel) only for the whole given Range
. 这意味着仅在整个给定Range
一个 内部对象(Excel) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.