Search code examples
excelvbacolors

Changing Cell colour using VBA in excel


Hi I am very new to VBA in excel and very rusty writing code in general. I have written code so that if I select cell A2 then Cells A5 and G5 turn yellow. Now I want to keep that selection but also turn for example G5 purple still having only selected A2. If this possible? Can you show me how? Thank you!

Current code:

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

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)