我正在尝试为作为参数传递给函数的单元格着色,但它似乎不起作用。这是代码:
Sub my_test(Target As Range)
With Target.Cells(1, 1).Interior
.ColorIndex = 3
.PatternColorIndex = xlAutomatic
End With
End Sub
Function f_Lookup_domain(P_Cell_name As Range, ByVal P_Default As String) As String
Call my_test(P_Cell_name)
v_Cell_name = P_Cell_name.Value
' Application.Volatile
'Lookup the domain of a signal from the cell name
'
v_temp = Application.VLookup(v_Cell_name, Range("n_IO_cell_lookup"), 2, False)
If Application.IsError(v_temp) Then
' cell given is not a real IO cell, try to use default
If P_Default = "CUT" Then
v_temp = "Unknown"
Else
v_temp = P_Default
End If
End If
f_Lookup_domain = v_temp
End Function
没有错误报告,该函数返回正确的值。调用my_test
,但单元格未绘制。如果我使用以下测试平台调用my_test
:
Sub Testbench()
Call my_test(Range("D10"))
End Sub
它确实为细胞着色。好像P_Cell_name
不像一个范围?任何人的想法?
答案 0 :(得分:1)
用户定义的函数称为无法修改范围或工作表的属性(与其值相关的属性除外),如果您尝试它将无声地失败。
Description of limitations of custom functions in Excel
Conditional Formatting功能可以提供帮助。