简体   繁体   English

彩色电池的VBA UDF

[英]VBA UDF for color cells

I'm sure my question is simple to most of you as I'm new to UDF. 我敢肯定,对于UDF来说,我的问题对大多数人来说都很简单。 I've created the following UDF but cannot apply it across columns when I use =CheckColor1(H13:M13) 我创建了以下UDF,但是当我使用= CheckColor1(H13:M13)时,无法将其跨列应用

Function CheckColor1(range)
    If range.Interior.Color = RGB(0, 176, 80) Then
        CheckColor1 = "Final"
    ElseIf range.Interior.Color = RGB(255, 255, 0) Then
        CheckColor1 = "Final"
    ElseIf range.Interior.Color = RGB(191, 191, 191) Then
        CheckColor1 = "Final"
    ElseIf range = 0 Then
        CheckColor1 = "Final"
    Else
        CheckColor1 = " "
    End If
End Function

You forgot to define your function's argument object or data type. 您忘记定义函数的参数对象或数据类型。

According to the syntax for procedural parameters, much like declaring variables, you must use the "As" to specify the type of your argument. 根据过程参数的语法,就像声明变量一样,您必须使用“ As”来指定参数的类型。

The argument must be declared as a normal variable, omitting the Dim keyword. 该参数必须声明为普通变量,并省略Dim关键字。

You cannot, however, use the name of the data or object type as the argument name itself which was what you were trying to do. 但是,您不能使用数据或对象类型的名称作为参数名称本身,而这正是您要尝试执行的操作。

Function CheckColor1(r as Range)
    If r.Interior.Color = RGB(0, 176, 80) Then
        CheckColor1 = "Final"
    ElseIf r.Interior.Color = RGB(255, 255, 0) Then
        CheckColor1 = "Final"
    ElseIf r.Interior.Color = RGB(191, 191, 191) Then
        CheckColor1 = "Final"
    ElseIf r.interior.colordindex = 0 Then
        CheckColor1 = "Final"
    Else
        CheckColor1 = " "
    End If
End Function

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM