excelvbacolors

Changing cell colour using VBA in Excel


I have written code so that if I select cell A2, cells A2, A5 and G5 turn yellow.

Select.Case Target.Adress
Case "$A$2" 
    .Range (A2,A5,G5).Interior.Color =RGB (255, 255, 0)

Is it possible to turn G5 purple still having only selected A2?


Solution

  • You can change color for each cell.

    Select Case Target.Adress
    Case "$A$2"
       .Range("A2,A5").Interior.Color = RGB(255, 255, 0)
       .Range("G5").Interior.Color = RGB(112, 48, 160)