Using the Interior Object to Alter the Background of a Range : Range Format « Excel « VBA / Excel / Access / Word






Using the Interior Object to Alter the Background of a Range

 
Sub InteriorExample() 
    Dim rg As Range 
    Set rg = ThisWorkbook.Worksheets("Sheet1").Range("A1").Offset(1, 0) 

    Do Until IsEmpty(rg) 
        rg.Offset(0, 2).Interior.Pattern = rg.Offset(0, 1).Value 
        rg.Offset(0, 3).Interior.Pattern = rg.Offset(0, 1).Value 
        rg.Offset(0, 3).Interior.PatternColor = vbRed 
        Set rg = rg.Offset(1, 0) 
    Loop 

    ' create examples of each VB defined color constant 
    Set rg = ThisWorkbook.Worksheets("Sheet1").Range("A1:E3").Offset(1, 0) 

    Do Until IsEmpty(rg) 
        rg.Offset(0, 2).Interior.Color = rg.Offset(0, 1).Value 
        Set rg = rg.Offset(1, 0) 
    Loop 

    Set rg = Nothing 
End Sub 

 








Related examples in the same category

1.Format current region
2.The Font property
3.Use the Range and Cells properties of the Worksheet object to return a Range object.
4.Sets to True the Bold property of the Font object contained in the Range object
5.The Interior property:changes the Color property of the Interior object contained in the Range object:
6.Specify colors with VBA's RGB function.
7.Formatting Range: HorizontalAlignment, VerticalAlignment, MergeCells
8.Formatting Range: Font
9.Changes font to bold
10.Changes color of numbers < 100
11.Set the color for whole range
12.Change range border style
13.Change range border color
14.Providing Dynamic Scaling to Your Worksheets
15.Strolling Through the Color Palette
16.Line style: xlContinuous
17.Line style: xlDash
18.Line style: xlDashDot
19.Line style: xlDashDotDot
20.Line style: xlDot
21.Line style: xlDouble
22.Line style: xlLineStyleNone
23.Line style: xlSlantDashDot
24.Set the underline, color and font name
25.Make column headings bold
26.Add & format totals
27.Format date on report
28.Widen first column to display text
29.Make text in first column bold