ColumnCount设置
系统:Windows 7 软件:Excel 2016
Part 1:实现功能
ColumnCount设置 报错 ListView查询静图 ListView查询动图 Part 2:ListView
添加新控件 ListView控件 成绩查询-ListView 控件对应变量名 Part 3:代码 主代码 Private Sub outputSearchV_Click() Set ctrlStudent = Me.Controls('outputStudentNameV') studentName = ctrlStudent.Value Set ctrlCourse = Me.Controls('outputCourseNameV') courseName = ctrlCourse.Value Set ctrlExam = Me.Controls('outputWhichExamV') exam = ctrlExam.Value If studentName = '' And courseName = '' And exam = '' Then MsgBox '请输入查询条件' Exit Sub End If Set ctrl = Me.Controls('outputListView') ' 清空原标题 ctrl.ColumnHeaders.Clear ' 加上标题 ctrl.ColumnHeaders.Add , , '序号' ctrl.ColumnHeaders.Add , , '姓名' ctrl.ColumnHeaders.Add , , '科目' ctrl.ColumnHeaders.Add , , '第几次模拟考' ctrl.ColumnHeaders.Add , , '成绩' ctrl.View = lvwReport ctrl.FullRowSelect = True ctrl.Gridlines = True '清空其它数据 ctrl.ListItems.Clear
Set shtDb = ThisWorkbook.Worksheets('学生成绩db') maxRow = shtDb.Cells(Rows.Count, 'B').End(xlUp).Row inputNum = 1 flag = 0 For i = 2 To maxRow Step 1 existStudent = shtDb.Cells(i, 'B') existCourse = shtDb.Cells(i, 'C') existExam = CInt(shtDb.Cells(i, 'D')) check = 条件检测(existStudent, existCourse, existExam, studentName, courseName, exam) If check = True Then existNote = shtDb.Cells(i, 'E') Set Item = ctrl.ListItems.Add() Item.Text = inputNum Item.SubItems(1) = existStudent Item.SubItems(2) = existCourse Item.SubItems(3) = existExam Item.SubItems(4) = existNote inputNum = inputNum + 1 flag = 1 End If Next i If flag = 1 Then MsgBox '查询完毕,请从下表查看结果' Else MsgBox '未查询到满足条件的结果' End If End Sub
代码截图 条件检测 函数
代码截图 Part 4:部分代码解读
Set Item = ctrl.ListItems.Add() Item.Text = inputNum Item.SubItems(1) = existStudent Item.SubItems(2) = existCourse Item.SubItems(3) = existExam Item.SubItems(4) = existNote 关闭整行选择和栅格线显示
|
|
来自: 書生的图书馆 > 《Excel vba》