如何使这项工作有效?
Range(Cells(1,1),Cells(height,width)).Interior.Color=colorArray
colorArray 是包含颜色值的长度(宽度*高度)长整型的一维数组。
上面的代码返回
类型不匹配错误。
For i = 1 to height
For j = 1 to width
t=(i-1)*width+j
Cells(i,j).Interior.Color=colorArray(t)
Next
Next
这段代码可以工作,但速度太慢。我不想使用循环。
Range(Cells(1,1),Cells(height,width)).Value=colorArray
此代码使用 colorArray 中的颜色值填充该范围,没有错误。我想要一个类似的代码来更改此范围的单元格的背景颜色。
请帮忙。
ReDim colorArray(1 To width*height) As Long
Siddharth Rout 的示例代码:
Sub Sample()
Dim colorArray(21) 'or Dim colorArray(21) As Long/Integer
Dim Height As Long, Width As Long
For i = 0 To 21
colorArray(i) = i
Next
Height = 10
Width = 2
Range(Cells(1, 1), Cells(Height, Width)).Interior.Color = colorArray
End Sub
此代码还返回
“运行时错误:‘13’类型不匹配”