ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Formatting from a Function (https://www.excelbanter.com/excel-discussion-misc-queries/62680-formatting-function.html)

VALid

Formatting from a Function
 

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




VALid

Formatting from a Function
 

Oh... Trivial!
Thanks a lot, I'll correct that way.

"Ron Rosenfeld" a écrit dans le message de news:
...
On Mon, 2 Jan 2006 14:34:04 +0100, "VALid" wrote:


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





Ron Rosenfeld

Formatting from a Function
 
On Mon, 2 Jan 2006 14:34:04 +0100, "VALid" wrote:


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

Ron Rosenfeld

Formatting from a Function
 
You're welcome. Glad to help.

On Mon, 2 Jan 2006 14:52:13 +0100, "VALid" wrote:


Oh... Trivial!
Thanks a lot, I'll correct that way.

"Ron Rosenfeld" a écrit dans le message de news:
...
On Mon, 2 Jan 2006 14:34:04 +0100, "VALid" wrote:


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




--ron


All times are GMT +1. The time now is 08:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com