When I use color number 15325914 directly it shades the cell in correct color (Light Grayish Blue).

Activecell.Interior.Color = 15325914

Light Grayish Blue:

Light Grayish Blue

When I use the same color number 15325914 when it is stored in a constant it shades the cell in black color (When it is already not in the 15325914 color).

Public Const LightGrayishBlue = 15325914
Activecell.Interior.Color = LightGrayishBlue

Black Color

1

There are 1 best solutions below

0
On BEST ANSWER

Your code should work when everything is setup correctly (have used similar code 1000nds of times).

The most likely reason is that LightGrayishBlue has the value 0 when assigned as interior color. But the black color can have several reasons:

  • You have a typo in the name or the constant is not available at your code. Always use Option Explicit to catch such cases.
  • you have a variable with the same name that "hides" the constant definition. Go to the VBA editor, move the mouse on the LightGrayishBlue and press Shift+F2 (goto definition): Does it jump to the Const definition or somewhere else? Or does it show an error "Identifier under cursor is not recognized"
  • What you also can do: Set a breakpoint to the statement setting the color and check with the debugger the content of LightGrayishBlue. Is it 0 or does it show the expected value?
  • Execute the statement (F8) that sets the color: Is the active cell now blue or black? Maybe some following code changes the color again.