1. 把将要进行条件查询的数据导入表格,如图所示。
2.在I3单元格中输入“=SUMIFS(A4:A26,B4:B26,B3,C4:C26,C3,D4:D26,D3,E4:E26,E3,F4:F26,F3,G4:G26,G3,H4:H26,H3)”。
3.现在分别在3行中输入条件,如图所示。
4.现在可以看到各科的几个的学生就查询出来了。
5.用同样的方法还可以查询其他条件下的值,如图所示。
6.还可以用“=”来查询一些特定的值,如图所示。
Private Sub CommandButton1_Click()
TextBox3.Text = ""
For r = 1 To Range("a65536").End(xlUp).Row
If Cells(r, 1).Value = TextBox1.Text And Cells(r, 2).Value = TextBox2.Text Then
TextBox3.Text = Cells(r, 3).Value
Exit For
End If
Next
End Sub