Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Column
Case Is > 2
Case Else
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 1) < 1 Or Cells(i, 2) < 0 Then
ElseIf Cells(i, 1) < 11 And Cells(i, 2) = 0 Then
Cells(i, 3) = 0
ElseIf Cells(i, 1) < 11 And Cells(i, 2) < 11 Then
Cells(i, 3) = 10
ElseIf Cells(i, 1) < 16 And Cells(i, 2) < 11 Then
Cells(i, 3) = 10
ElseIf Cells(i, 1) < 16 And Cells(i, 2) < 16 Then
Cells(i, 3) = 15
ElseIf Cells(i, 1) < 16 Then
Cells(i, 3) = 10
ElseIf Cells(i, 1) < 21 And Cells(i, 2) < 16 Then
ElseIf Cells(i, 1) < 21 And Cells(i, 2) < 21 Then
Cells(i, 3) = 20
ElseIf Cells(i, 1) >= 21 And Cells(i, 2) >= 20 Then
Cells(i, 3) = 30
End If
Next
End Select
End Sub
'下图是我的测试结果
或者说我再猜测下你的需求,是不是这样的
猜测三:按出勤和业绩里面最低的来,哪个低算哪个,然后最低的那一项满足为0的话单价是0,1-10的话单价是10,11-15的话单价是15,16-20的话单价是20,21以上的话单价是30。
像我这样说是不是一句话就讲清楚了。
如果是猜测三的话代码应该修改为
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Column
Case Is > 2
Case Else
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
Mini = Cells(i, 1)
If Cells(i, 1) > Cells(i, 2) Then Mini = Cells(i, 2)
Select Case Mini
Case Is < 1
Cells(i, 3) = 0
Case Is < 11
Cells(i, 3) = 10
Case Is < 16
Cells(i, 3) = 15
Case Is < 21
Cells(i, 3) = 20
Case Else
Cells(i, 3) = 30
End Select
Next
End Select
End Sub
'