0

I have searched everywhere for an answer to this issue and I am fairly new to VBA so I hope you can help. Below is the code.

If [e19].Value + [g19].Value = [c19].Value Then
[l19].Value = "Yes"
ElseIf [e19].Value = "N/A" Then
[l19].Value = "N/A"
**ElseIf Range("i18:i21, l18").Value = "{a}" Then**
l19.Value = "{b}"

The code wrapped in ** is where I am having my issue. Any ideas?

Thank you

4

1 回答 1

0

您不能将范围与特定值进行比较。您可以将每个单元格放在“For Each xxx In Range.Cells...Next”语句中,以继续比较范围内的每个值,但请注意,每个依次单独比较单元格。这段代码应该这样工作:

Sub zo()
If [e19].Value + [g19].Value = [c19].Value Then
    [l19].Value = "Yes"
ElseIf [e19].Value = "N/A" Then
    [l19].Value = "N/A"
Else
    For Each cell In Range("i18:i21, l18")
        If cell.Value = "{a}" Then
            [l19].Value = "{b}"
        End If
    Next
End If
End Sub
于 2013-07-16T19:30:36.773 回答