View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Set cell color with VBA results in "#VALUE!"

Try these

MsgBox Cells(1, 1).Interior.ColorIndex
Cells(1, 1).Interior.ColorIndex = 10

Mike

"Christian Schratter" wrote:

Hello

I made a function in a new module with a function which looks like this:

Public Function testColor()

MsgBox Cells(1, 1).Interior.Color 'does work - displays e.g. 255
Cells(1, 1).Interior.Color = 10 'does NOT work - displays "#VALUE!"
in the calling cell

End Function

This function gets called in a cell ("=testColor()").
The target would be to change the color of a cell with this VBA function.
Sadly setting the color does not work, while I can perfectly read the
color-code.

Where's the mistake here? I'm using Excel 2007.