Excel 2007 conditional formatting - how to get cell color?

后端 未结 7 1294
别那么骄傲
别那么骄傲 2020-12-06 02:17

Let\'s assume i have the following range from (a1:c3)

  A B C
1 -1 1 1
2 -1 0 0
3  0 0 1

Now i have selected the following range, and forma

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 02:24

    To get the color of a cell in a Range, you need to reference the individual cell inside the array in the form of Range("A1","C3").Cells(1,1) (for cell A1). The Excel help is pretty good if you look up the name of the property you're having issues with.

    Also, Excel 2007 uses Integers for its color types, so your best bet is to assign the color index to an integer, and using that throughout your program. For your example, try:

    Green = Range("A1","C3").Cells(1,1).Interior.Color
    Yellow = Range("A1","C3").Cells(1,3).Interior.Color
    Red = Range("A1","C3").Cells(2,1).Interior.Color
    

    And then to switch the colors to all red:

    Range("A1","C3").Interior.Color = Red
    

    Again, check the Excel help for how to use Cells([RowIndex],[ColumnIndex]).

    If the above doesn't work for you, check to see what .Interior.PatternColorIndex is equal to. I typically leave it set at xlAutomatic (solid color), and it could be set to something else if the color isn't changing.

提交回复
热议问题