这是我的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
答案 0 :(得分:3)
非VBA方式
将此公式放入单元格C1
并将其拉下
=IF(OR(A1<15,B1<15),"Pass","")
然后使用主页 | 条件格式到颜色C
列
VBA Way
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