I'd never tried this before, but decided I'd like to change the background or text color in the cell via a function call, depending upon the value of one of the arguments supplied to the function AL(uH,Turns).
This should be really simple; I just haven't tried to do this before and I am not certain how the cell range (where the function was called from) could be passed to the function, without having to actually enter it into the formula.
This is what I've been fiddling with:
I'd found this snippet in the help file:
This should be really simple; I just haven't tried to do this before and I am not certain how the cell range (where the function was called from) could be passed to the function, without having to actually enter it into the formula.
This is what I've been fiddling with:
Rich (BB code):
Function AL(uH, Turns)
If Turns > 0 Then
AL = uH * 1000 / (Turns * Turns)
Else
AL = 0
End If
Select Case AL
Case Is < 1
AL = 0
CI = 10
Case Is < 10
CI = 27
Case Else
CI = 28
End Select
With Selection.Interior
.ColorIndex = CI
.Pattern = xlSolid
End With
Selection.Interior.ColorIndex = CI
End Function
Rich (BB code):
Using the Interior Object
Use the Interior property to return the Interior object. The following example sets the color for the interior of cell A1 to red.
Worksheets("Sheet1").Range("A1").Interior.ColorIndex = 3