Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default UFD to change color based on string

ok, I keep getting =Name? and I'm not sure if this is even going to work.
Any help would be appreciated. Tried figuring this out on my own and not
having much luck.
Basically Text in A1 has USD or CDN or something else, if USD change color
of A1 to 5 and the neighbouring cells color changes to 5. (The text not the
background).

Function ColChange(r1 As Variant)

Select Case r1.Text
Case "USD"
r1.Font.ColorIndex = 5
r1.Offset(1, 2).Font.ColorIndex = 5
Case "CAD"
r1.Font.ColorIndex = 3
r1.Offset(1, 2).Font.ColorIndex = 3
Case Else
r1.Font.ColorIndex = xlNone
r1.Offset(1, 2).Font.ColorIndex = 5
End Select
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default UFD to change color based on string

I had the conditional formating doing this before, but you can't have excel
add based on color that way. Hmm.. What about using the USD or CDN then
doing the offset thing to add according to country? That should work and I
could still use the Conditional formating.. Hmm... The range varies each
time, I could still use the function CASE, do a loop, hmm.. Any pit falls I
might run into this this?

"Tom Ogilvy" wrote:

I assume you want to use this function in a worksheet. You probably have it
in a sheet module. That will cause a #Name error - it should be in a general
module

all that said,
You should use conditional formatting to do this.

A UDF used in a worksheet can only return a value to a cell - it can't put
values in other cells or change colors in any cell or otherwise alter the
Excel environment.

--
Regards,
Tom Ogilvy



"Mitch" wrote:

ok, I keep getting =Name? and I'm not sure if this is even going to work.
Any help would be appreciated. Tried figuring this out on my own and not
having much luck.
Basically Text in A1 has USD or CDN or something else, if USD change color
of A1 to 5 and the neighbouring cells color changes to 5. (The text not the
background).

Function ColChange(r1 As Variant)

Select Case r1.Text
Case "USD"
r1.Font.ColorIndex = 5
r1.Offset(1, 2).Font.ColorIndex = 5
Case "CAD"
r1.Font.ColorIndex = 3
r1.Offset(1, 2).Font.ColorIndex = 3
Case Else
r1.Font.ColorIndex = xlNone
r1.Offset(1, 2).Font.ColorIndex = 5
End Select
End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default UFD to change color based on string

Please disregard, found the SUMIF function. Works like a charm.

"Tom Ogilvy" wrote:

I assume you want to use this function in a worksheet. You probably have it
in a sheet module. That will cause a #Name error - it should be in a general
module

all that said,
You should use conditional formatting to do this.

A UDF used in a worksheet can only return a value to a cell - it can't put
values in other cells or change colors in any cell or otherwise alter the
Excel environment.

--
Regards,
Tom Ogilvy



"Mitch" wrote:

ok, I keep getting =Name? and I'm not sure if this is even going to work.
Any help would be appreciated. Tried figuring this out on my own and not
having much luck.
Basically Text in A1 has USD or CDN or something else, if USD change color
of A1 to 5 and the neighbouring cells color changes to 5. (The text not the
background).

Function ColChange(r1 As Variant)

Select Case r1.Text
Case "USD"
r1.Font.ColorIndex = 5
r1.Offset(1, 2).Font.ColorIndex = 5
Case "CAD"
r1.Font.ColorIndex = 3
r1.Offset(1, 2).Font.ColorIndex = 3
Case Else
r1.Font.ColorIndex = xlNone
r1.Offset(1, 2).Font.ColorIndex = 5
End Select
End Function

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
How to change color within string? Eric Excel Discussion (Misc queries) 2 March 18th 10 08:33 AM
Change tab color based on current color of a cell MarkT Excel Discussion (Misc queries) 0 May 22nd 08 05:46 PM
UFD to change color based on string Tom Ogilvy Excel Programming 0 September 28th 07 04:43 PM
change fill color of a range of cells based on color of a cell? DarMelNel Excel Programming 0 March 2nd 06 06:35 PM
Browse Forms Controls and change TextBox color based on cell color StefanW Excel Programming 2 November 21st 04 07:06 PM


All times are GMT +1. The time now is 01:13 PM.

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"