首页 > 解决方案 > Can someone provide the technical reason why the `Interior.Color` property can't be assigned from one range to another in Excel VBA?

问题描述

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

标签: excelvbaformat

解决方案


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.


推荐阅读