Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Wazooli
 
Posts: n/a
Default setting cell color

I have been using the following code, as posted in this usergroup recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow me to
assign a color to a cell via a UDF?

Thanks,

Wazooli
  #2   Report Post  
Wazooli
 
Posts: n/a
Default

And, P.S. - I don't want to do this via conditional formatting. I would like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow me to
assign a color to a cell via a UDF?

Thanks,

Wazooli

  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

No, because UDFS return a value, they do not change worksheet attributes.

--
HTH

Bob Phillips

"Wazooli" wrote in message
...
And, P.S. - I don't want to do this via conditional formatting. I would

like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup

recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow me

to
assign a color to a cell via a UDF?

Thanks,

Wazooli



  #4   Report Post  
Wazooli
 
Posts: n/a
Default

So then there is no way to assign a color to a cell using VBA?

Wazooli

"Bob Phillips" wrote:

No, because UDFS return a value, they do not change worksheet attributes.

--
HTH

Bob Phillips

"Wazooli" wrote in message
...
And, P.S. - I don't want to do this via conditional formatting. I would

like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup

recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow me

to
assign a color to a cell via a UDF?

Thanks,

Wazooli




  #5   Report Post  
Numfric
 
Posts: n/a
Default

Sub Color_red()
'
' Color_red Macro
' Set cell color to red
'

'
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub

"Wazooli" wrote:

So then there is no way to assign a color to a cell using VBA?

Wazooli

"Bob Phillips" wrote:

No, because UDFS return a value, they do not change worksheet attributes.

--
HTH

Bob Phillips

"Wazooli" wrote in message
...
And, P.S. - I don't want to do this via conditional formatting. I would

like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup

recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow me

to
assign a color to a cell via a UDF?

Thanks,

Wazooli






  #6   Report Post  
Peo Sjoblom
 
Posts: n/a
Default

That's not what you asked and what Bob answered to, you asked if it was
possible using a UDF
to use a macro see:

http://www.mvps.org/dmcritchie/excel/colorrng.htm

http://www.mvps.org/dmcritchie/excel/colors.htm

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)



"Wazooli" wrote in message
...
So then there is no way to assign a color to a cell using VBA?

Wazooli

"Bob Phillips" wrote:

No, because UDFS return a value, they do not change worksheet attributes.

--
HTH

Bob Phillips

"Wazooli" wrote in message
...
And, P.S. - I don't want to do this via conditional formatting. I
would

like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup

recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow
me

to
assign a color to a cell via a UDF?

Thanks,

Wazooli






  #7   Report Post  
Wazooli
 
Posts: n/a
Default

Thanks Peo. I will try to use some of what is on the second link you
supplied, although you shouldn't be surprised if I am back here asking
questions.

wazooli

"Peo Sjoblom" wrote:

That's not what you asked and what Bob answered to, you asked if it was
possible using a UDF
to use a macro see:

http://www.mvps.org/dmcritchie/excel/colorrng.htm

http://www.mvps.org/dmcritchie/excel/colors.htm

--
Regards,

Peo Sjoblom

(No private emails please, for everyone's
benefit keep the discussion in the newsgroup/forum)



"Wazooli" wrote in message
...
So then there is no way to assign a color to a cell using VBA?

Wazooli

"Bob Phillips" wrote:

No, because UDFS return a value, they do not change worksheet attributes.

--
HTH

Bob Phillips

"Wazooli" wrote in message
...
And, P.S. - I don't want to do this via conditional formatting. I
would
like
to learn how to do it with VBA.

Wazolli

"Wazooli" wrote:

I have been using the following code, as posted in this usergroup
recently:

Public Function GetCellColor(MyCell As Range) As Variant
GetCellColor = MyCell.Interior.ColorIndex
End Function

This works great, and allows me to use the cell color as a downstream
condition. Is there a similarly succint bit of code that will allow
me
to
assign a color to a cell via a UDF?

Thanks,

Wazooli






  #8   Report Post  
Ola
 
Posts: n/a
Default

Is it possible to make this work?

Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
MyCell.Interior.ColorIndex = Color
If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
End Function

Ola

  #9   Report Post  
Bob Phillips
 
Posts: n/a
Default

See my reply to Waxooli.

--
HTH

Bob Phillips

"Ola" wrote in message
...
Is it possible to make this work?

Public Function ColorCell(MyCell As Range, Color, Optional Message) As

Variant
MyCell.Interior.ColorIndex = Color
If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
End Function

Ola



  #10   Report Post  
Numfric
 
Posts: n/a
Default

Yes (with slight correction):

Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
MyCell.Interior.ColorIndex = Color
If IsEmpty(Message) Then MyCell = "" Else MyCell = Message
End Function
Sub Color_red()
'
' Color_red Macro
' Set cell color to red
'

'
Dim x As Variant
x = ColorCell(Range("a2:a7"), 3, "This should be red")
End Sub

"Ola" wrote:

Is it possible to make this work?

Public Function ColorCell(MyCell As Range, Color, Optional Message) As Variant
MyCell.Interior.ColorIndex = Color
If IsEmpty(Message) Then ColorCell = "" Else ColorCell = Message
End Function

Ola

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
Change cell back color on click Dave Peterson Excel Discussion (Misc queries) 0 January 24th 05 10:50 PM
Color change in cell when > 49.99 Slumbering Gorilla Excel Discussion (Misc queries) 1 January 24th 05 08:11 PM
Current Cell Color mike47338 Excel Worksheet Functions 5 December 10th 04 06:45 PM
cell color shading stacydoo Excel Discussion (Misc queries) 1 December 10th 04 07:44 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


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

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

About Us

"It's about Microsoft Excel"