统计每行对勾的数量,大于2的弹窗提醒。如图:
对应vba代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = application.WorksheetFunction.CountIf(Worksheets("Sheet1").Range(Cells(4, 4), Cells(4, 7)), "√")
If i > 2 Then
MsgBox "选择超过两项!"
End If
End Sub
选择G3:O1000(最大行)
然后选择数据菜单中的:“数据有效性”
选择自定义,然后输入公式:=COUNTA($G3:$O3)<3
就可以了
选取G3:O12,在“数据有效性”中输入公式
=COUNTA($G3:$O3)<3
设置数据有效性
=COUNTIF(E2:L2,"√")<=2