Vba Excel宏检查前两行值小于15

Vba Excel宏检查前两行值小于15,vba,excel,Vba,Excel,这是我的excel宏代码,我需要检查前两行,如果值小于15,则显示第三行“通过”。现在我已经做了,但它只工作了一行。但我必须检查整行和整列,我如何才能做到这一点。伙计们帮帮我 Dim result As String Dim score As Integer Dim score1 As Integer Sub wewew() score = Range("A1").Value score1 = Range("B1").Value If score < 15 Or score1 <

这是我的excel宏代码,我需要检查前两行,如果值小于15,则显示第三行“通过”。现在我已经做了,但它只工作了一行。但我必须检查整行和整列,我如何才能做到这一点。伙计们帮帮我

Dim result As String
Dim score As Integer
Dim score1 As Integer

Sub wewew()

score = Range("A1").Value
score1 = Range("B1").Value
If score < 15 Or score1 < 15 Then result = "pass"

Range("C1").Value = result
    Range("C1").Interior.Color = RGB(255, 0, 0)

End Sub
Dim结果为字符串
将分数设置为整数
1作为整数
次级WEW()
分数=范围(“A1”)。数值
分数1=范围(“B1”).值
如果分数<15或分数1<15,则结果=“通过”
范围(“C1”)。值=结果
范围(“C1”).Interior.Color=RGB(255,0,0)
端接头

非VBA方式

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long, i As Long

    Set ws = Sheet1 '<~~ Set this to the relevant worksheet

    With ws
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row '<~~ Find Last Row

        For i = 1 To lRow
            If .Range("A" & i).Value < 15 Or .Range("B" & i).Value < 15 Then
                With .Range("C" & i)
                    .Value = "Pass"
                    .Interior.Color = RGB(255, 0, 0)
                End With
            End If
        Next i
    End With
End Sub
将此公式放入单元格
C1
,然后将其向下拉

=IF(OR(A1<15,B1<15),"Pass","")

Siddharth Rout非常感谢哥们:)它起作用了:)你帮了我很多忙:)谢谢:)@pnuts:忙着做项目。。。也许很快就要回去了:好吧,兄弟:)不管怎样,你救了我很多。我挣扎了5个多小时,现在我必须放松我的椅子:)