Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

excel - Function colors cells which match specific condition

I want to code a function color_yellow(table As Range) which outputs table with colored cells in which numbers are smaller than 0.5.

Example

enter image description here

My pseudo code :

Function color_yellow(table As Range)
    Dim temp As Variant, i As Long
    temp = table.Value

    For i = 1 To UBound(temp, 1)
        If temp(i, 1) < 0.5 Then
           fill_with_yellow (temp(i, 1))
        End If
    Next
   
    color_yellow = temp

End Function

I called it 'pseudo code' because there is no such function as fill_with_yellow. Do you know by what should I replace fill_with_yellow(temp(i,1)) to get expected result ?

EDIT

Using conditional formatting : I found that color which interests me has number 65535.

I know that If I want to have my condition I only have to use :

With Cells(1, 1).FormatConditions.add(xlCellValue, xlLess, "=0.5")
    .Color = 65535
    .StopIfTrue = False
End With

But I'm not sure how to add this to my function color_yellow.

question from:https://stackoverflow.com/questions/65598286/function-colors-cells-which-match-specific-condition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...