简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM