Formatting from a Function

V

VALid

Hi,

I wrote that very simple function.... which does NOT work.
Any idea why??? Thanks.

Public Function SetCellColor(ByVal AnIndex As Long)
'Application.Volatile (True)
With Selection.Interior
.ColorIndex = AnIndex
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
SetCellColor = AnIndex
End Function
 
R

Ron Rosenfeld

Hi,

I wrote that very simple function.... which does NOT work.
Any idea why??? Thanks.

Public Function SetCellColor(ByVal AnIndex As Long)
'Application.Volatile (True)
With Selection.Interior
.ColorIndex = AnIndex
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
SetCellColor = AnIndex
End Function

A function can only return a value.

You need to formulate a Sub in order to affect a cell's appearance.


--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top