Home / User Contributed Macros / Lightening Colors

Lightening Colors


Macro to create lighter shades of a color:
Option Explicit
Sub lightenRGB()
 Dim I As Integer, Rng As Range
 Dim R As Byte, G As Byte, B As Byte
 Set Rng = Selection
 
 With Rng.Cells(1).Interior
       R = .Color Mod 256
     G = .Color \ 256 Mod 256
     B = .Color \ (CLng(256) * 256)
 End With
 
 For I = 2 To Rng.Cells.Count
     With Rng.Cells(I).Interior
          .Color = RGB(R + (255 - R) * (I - 1) / (Rng.Cells.Count - 1), _
                 G + (255 - G) * (I - 1) / (Rng.Cells.Count - 1), _
                 B + (255 - B) * (I - 1) / (Rng.Cells.Count - 1))
     End With
 Next I
End Sub
 
Courtesy: http://www.dailydoseofexcel.com/archives/2010/08/06/lightening-colors/



     RSS of this page