【发布时间】:2012-03-08 15:57:55
【问题描述】:
如何做到这一点?
Range(Cells(1,1),Cells(height,width)).Interior.Color=colorArray
colorArray 是包含颜色值的长度 (width*height) 长整数的一维数组。
以上代码返回
类型不匹配错误。
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’类型不匹配”
【问题讨论】:
-
嗯,这令人惊讶。我重新测试了我的代码,它工作得很好。您可以在 www.wikisend.com 上上传您的工作簿并将链接粘贴到此处以便我查看吗?