Excelmacros检查前两行值小于15

这里是我的Excelmacros编码,我需要检查前两行任何值小于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 

非VBA方式

把这个公式放在C1单元格中,然后拉下来

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

然后使用Home | 条件格式化C列的颜色

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