다음을 통해 공유


Interior Object (Excel)

Represents the interior of an object.

Example

Use the Interior property to return the Interior object. The following example sets the color for the interior of cell A1 to red.

Worksheets("Sheet1").Range("A1").Interior.ColorIndex = 3

Sample code provided by: Holy Macro! Books, Holy Macro! It’s 2,500 Excel VBA Examples | About the Contributor

This example gets the value of the color of a cell in column A using the ColorIndex property, and then uses that value to sort the range by color.

Sub ColorSort()
   'Set up your variables and turn off screen updating.
   Dim iCounter As Integer
   Application.ScreenUpdating = False
   
   'For each cell in column A, go through and place the color index value of the cell in column C.
   For iCounter = 2 To 55
      Cells(iCounter, 3) = _
         Cells(iCounter, 1).Interior.ColorIndex
   Next iCounter
   
   'Sort the rows based on the data in column C
   Range("C1") = "Index"
   Columns("A:C").Sort key1:=Range("C2"), _
      order1:=xlAscending, header:=xlYes
   
   'Clear out the temporary sorting value in column C, and turn screen updating back on.
   Columns(3).ClearContents
   Application.ScreenUpdating = True
End Sub

About the Contributor

Holy Macro! Books에서는 Microsoft Office 사용자를 위한 재미있는 서적을 다수 출판하고 있습니다. 전체 카탈로그는 MrExcel.com(영문일 수 있음)에서 확인할 수 있습니다.

참고 항목

개념

Excel Object Model Reference

Interior Object Members