I'm sure my question is simple to most of you as I'm new to UDF. I've created the following UDF but cannot apply it across columns when I use =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.
The argument must be declared as a normal variable, omitting the Dim keyword.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.