Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Getting a function to return a formated Range string

How do I get a function to return a formatted string for display in the
cell?
A1 has "=RollupStatus(A2:A5)"
A2 is GREEN background
A3 is YELLOW background
A4 is RED background
A5 is GREEN background
I want A1 to contain #### where 2 of the # characters are GREEN, 1 is Yellow
and 1 is RED

The function I wrote appears below. The problem I have is getting it to
return the formatted string. I've not initialized the range called
RollupStatus properly and I don't know how to correct it. My function code
is:

Function RollupStatus(InRange As Range) As Range
' This function counts the number of colour cells in InRange and
' sets a status string to match the range status.
' This doesn't deal with blank colour yet... xlColorIndexNone

Dim Rng As Range

Application.Volatile True
colourindex = 0
StartIndex = 0

Do While colourindex <= 56
CountByColor = 0
For Each Rng In InRange.Cells
' count each cell in range that matches current colourindex
CountByColor = CountByColor - (Rng.Interior.ColorIndex = colourindex)
Next Rng
If CountByColor 0 Then
RollupStatus.FormulaR1C1 = RollupStatus.FormulaR1C1 &
String$(CountByColor, "#")
RollupStatus.Characters(Start:=StartIndex, Length:=CountByColor).Font
StartIndex = StartIndex + CountByColor
End If
colourindex = colourindex + 1 ' switch to next colour
Loop
End Function


Can anyone help me?

Thanks
Bob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Getting a function to return a formated Range string

Hi bob
a function can only return values. So you can't return a formated
string as result of a function. You may use either conditional format
or use the worksheet_change event

Frank

Bob Hillier wrote:
How do I get a function to return a formatted string for display in
the cell?
A1 has "=RollupStatus(A2:A5)"
A2 is GREEN background
A3 is YELLOW background
A4 is RED background
A5 is GREEN background
I want A1 to contain #### where 2 of the # characters are GREEN, 1 is
Yellow and 1 is RED

The function I wrote appears below. The problem I have is getting it
to return the formatted string. I've not initialized the range called
RollupStatus properly and I don't know how to correct it. My function
code is:

Function RollupStatus(InRange As Range) As Range
' This function counts the number of colour cells in InRange and
' sets a status string to match the range status.
' This doesn't deal with blank colour yet... xlColorIndexNone

Dim Rng As Range

Application.Volatile True
colourindex = 0
StartIndex = 0

Do While colourindex <= 56
CountByColor = 0
For Each Rng In InRange.Cells
' count each cell in range that matches current colourindex
CountByColor = CountByColor - (Rng.Interior.ColorIndex =
colourindex) Next Rng
If CountByColor 0 Then
RollupStatus.FormulaR1C1 = RollupStatus.FormulaR1C1 &
String$(CountByColor, "#")
RollupStatus.Characters(Start:=StartIndex,
Length:=CountByColor).Font StartIndex = StartIndex + CountByColor
End If
colourindex = colourindex + 1 ' switch to next colour
Loop
End Function


Can anyone help me?

Thanks
Bob



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
EXCEL function;find string in entire column & return cell referenc Audit Compliance Man Excel Worksheet Functions 2 April 21st 23 10:24 AM
Return a String in a 7 Row Range Q Sean Excel Worksheet Functions 6 October 6th 08 03:36 PM
function like INDIRECT to return a range? Wilba Excel Worksheet Functions 4 November 17th 07 04:42 AM
return cell address of longest text string in a range Dave F[_2_] Excel Discussion (Misc queries) 2 July 12th 07 03:41 PM
Return string array from function in excel 97 Stelio Excel Programming 1 December 4th 03 11:40 AM


All times are GMT +1. The time now is 12:06 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"