Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default cell color within a function

Hello,
Is it possible to change a cell interior color within a function or must
that be done throught a sub.
thanks
billq


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default cell color within a function

you can do it in code, or use Conditional Formatting -
though this only allows three conditions.

Sub ColorTest()
Dim i As Long
On Error Resume Next
Do
Cells(i + 1, 1) = i
Cells(i + 1, 2).Interior.ColorIndex = i
i = i + 1
Loop While Err.Number = 0

End Sub

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Hello,
Is it possible to change a cell interior color within a

function or must
that be done throught a sub.
thanks
billq


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default cell color within a function

Hi Bill,

No. A function cannot change the contents or format of a cell.

Regards

Dave


"billQ" wrote in message
...
Hello,
Is it possible to change a cell interior color within a function or must
that be done throught a sub.
thanks
billq




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default cell color within a function

Bill,

Why not use CF as Patrick suggests.

With A1:A4 selected, go to FormatConditional Formatting
For Condition1
Choose FormulaIs
Add a formula of =MOD(ROW(),2)=0
Select the format button, pattern tab an d set the colour
OK
For Condition2, repeat with a formula of =MOD(ROW(),2)=1 and a different
colour

This CF can be copied as the range changes

--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"billQ" wrote in message
...
Hi Patrick,
I can do the change of color through a sub. I have a formula which
calculates the sum of a range, where I would like to alternate the colors

of
the range after summing. The range is dynamic so I was planning on
alternating the colors within the function.

Function myFunc() As Boolean
Dim rgn As Range
Dim color As Boolean
color = True
Set rgn = Range("A1:A4")
For Each cell In rgn
If color = True Then
cell.Interior.ColorIndex = 15
color = False
ElseIf color = False Then
cell.Interior.ColorIndex = 2
color = True
End If
Next cell
my = color
End Function
The code does not affect the cell within the range when I place =myFunc()

in
any cell.
thanks
billq
"billQ" wrote in message
...
Hello,
Is it possible to change a cell interior color within a function or must
that be done throught a sub.
thanks
billq






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function to change cell color ali Excel Worksheet Functions 1 September 12th 07 09:14 AM
IF function for cell color Clark Excel Worksheet Functions 1 May 22nd 06 09:43 PM
Cell Color Function? DTTODGG New Users to Excel 10 November 18th 05 05:23 PM
use if function to change cell color bigdaddy3 Excel Worksheet Functions 2 September 16th 05 11:36 AM
color of a cell within a nested if function Ian Excel Discussion (Misc queries) 2 May 22nd 05 12:57 AM


All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"