79374974

Date: 2025-01-21 15:27:00
Score: 1
Natty:
Report link

Why don't you use the Color property but ColorIndex?

Sub ChangeColor(addr, color_result As Long)
     addr.Interior.Color = color_result
End Sub

Public Function VLookupCC(lookup_value As Variant, lookup_range As Range, column_index As Long) As Variant

Dim i As Long
Dim color_result As Long, color_idx_result As Long

If column_index < 1 Or column_index > lookup_range.Columns.Count Then
    VLookupCC = CVErr(xlErrValue)
    Exit Function
End If
On Error Resume Next
i = Application.Match(lookup_value, lookup_range.Columns(1), 0)
On Error GoTo 0
If i <> 0 Then
    VLookupCC = lookup_range.Cells(i, column_index).Value
    color_result = lookup_range.Cells(i, column_index).Interior.Color
    If lookup_range.Cells(i, column_index).Interior.ColorIndex = xlColorIndexNone Then
        color_result = xlColorIndexNone
    End If
Else
    VLookupCC = CVErr(xlErrNA)
    color_result = xlColorIndexNone
End If
Evaluate "ChangeColor(" & Application.Caller.Address & ", " & color_result & ")"
End Function
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Starts with a question (0.5): Why don't you use the
Posted by: MGonet