有人可以提供不能在Excel VBA中将"Interior.Color"属性从一个范围分配到另一个范围的技术原因吗? [英] Can someone provide the technical reason why the `Interior.Color` property can't be assigned from one range to another in Excel VBA?

查看:43
本文介绍了有人可以提供不能在Excel VBA中将"Interior.Color"属性从一个范围分配到另一个范围的技术原因吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了链接使用剪贴板来传输格式(这可能是我最终要做的事情),但是我想知道为什么可以通过引用分配值而不能分配格式的技术原因.

换句话说,这为什么起作用...

Sheets("Sheet2").Range("A1:B10").Value = Sheets("Sheet1").Range("D1:E10").Value

这会失败吗?...

Sheets("Sheet2").Range("A1:B10").Interior.Color = Sheets("Sheet1").Range("D1:E10").Interior.Color

解决方案

简而言之, Interior.Color 仅返回一种颜色,而不返回颜色数组.

因此,这仅在所有源目标单元格的 Interior.Color 相同时有效.

由于 Interior.Color 不返回不同颜色的数组,如果颜色在源目标单元格中​​不匹配,则将返回 0 .

>

I've seen this link describing using the clipboard to transfer formats (and this is probably what I'll end up having to do), but I'd like to know the technical reason why values can be assigned by reference and formats can't.

In other words, why does this work...

Sheets("Sheet2").Range("A1:B10").Value = Sheets("Sheet1").Range("D1:E10").Value

and this fail?...

Sheets("Sheet2").Range("A1:B10").Interior.Color = Sheets("Sheet1").Range("D1:E10").Interior.Color

解决方案

In short, Interior.Color only returns one color, not an array of colors.

So this only works if the Interior.Color is the same for all of the source target cells.

Since Interior.Color doesn't return an array of differing colors, it will return 0 if the colors don't match across the source target cells.

这篇关于有人可以提供不能在Excel VBA中将"Interior.Color"属性从一个范围分配到另一个范围的技术原因吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆