|
楼主 |
发表于 2024-4-6 21:56
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub UserForm_Initialize()
Dim ar As Variant
Dim br()
rr = Array("节次", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日")
With Sheets("汇总")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(4, Columns.Count).End(xlToLeft).Column
ar = .Range(.Cells(1, 1), .Cells(r, y))
For j = 0 To UBound(rr)
ListView1.ColumnHeaders.Add , , rr(j), 90 'Sheets("物料库存数据").Cells(3, j).Width
Next
ListView1.View = lvwReport
ListView1.FullRowSelect = True
ListView1.Gridlines = True
ReDim br(1 To 14, 1 To 8) '14是课表最后一节所在的列号,如果节次有变化就修改这个值。
br(1, 1) = "节次"
For j = 2 To 14 '14是课表课表最后一节所在的列号,如果节次有变化就修改这个值。
br(j, 1) = ar(4, j)
Next j
zd = ActiveCell.Value
xm = Split(zd, Chr(10))(1)
y = 1
For j = 2 To UBound(ar, 2) Step 13
y = y + 1
For s = j To j + 12 '12是正课与晚自习的总节数,如果节数有变化就修改这个值。
If IsNumeric(ar(4, s)) Then
xh = ar(4, s) + 2
ElseIf ar(4, s) = "早读" Then
xh = 2
ElseIf InStr(ar(4, s), "晚") > 0 Then
xh = Right(ar(4, s), 1) + 11 '11是晚自习第一节的位置列号,如果有变化就修改这个值。
End If
For i = 5 To UBound(ar)
If ar(i, s) <> "" Then
If InStr(ar(i, s), Chr(10)) > 0 Then
If InStr(ar(i, s), xm) > 0 Then
br(xh, y) = Split(ar(i, s), Chr(10))(0) & ar(i, 1)
End If
End If
End If
Next i
Next s
Next j
For i = 2 To UBound(br)
Set Itm = ListView1.ListItems.Add
Itm.text = br(i, 1)
For j = 2 To UBound(br, 2)
Itm.SubItems(j - 1) = br(i, j)
Next j
Next i
End With
End Sub
老师好,您的代码我这样理解对吗,如果正确的话,我以后只要直接修改参数就行了
|
|