|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 查询打印()
Application.ScreenUpdating = False
Dim ar As Variant
Dim arr()
With Sheets("在校学生数据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:i" & r)
nj = .[k2]
bj = .[l2]
zx = .[m2]
zzx = .[n2]
xq = .[o2]
xx = .[p2]
bz = .[q2]
End With
ReDim arr(1 To UBound(ar), 1 To 4)
For i = 2 To UBound(ar)
If VBA.Trim(ar(i, 5)) = VBA.Trim(nj) And VBA.Trim(ar(i, 6)) = VBA.Trim(bj) And VBA.Trim(ar(i, 8)) = VBA.Trim(zx) And VBA.Trim(ar(i, 9)) = VBA.Trim(zzx) Then
n = n + 1
For j = 2 To 4
arr(n, j - 1) = ar(i, j)
Next j
arr(n, 4) = ar(i, 7)
End If
Next i
If n = "" Then MsgBox "没有符合条件的数据!": End
With Sheets("营养餐花名册")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs >= 30 Then .Rows("30:" & rs).Delete
.Range("b5:m19") = Empty
If n <= 15 Then
.[b5].Resize(n, 4) = arr
.[b2] = bj
For i = 5 To n + 4
For j = 6 To 10
.Cells(i, j) = bz
Next j
.Cells(i, 11) = bz * 5
Next i
ElseIf n > 15 Then
If Int(n / 15) = n / 15 Then
gs = n / 15
Else
gs = Int(n / 15) + 1
End If
m = 30
For i = 1 To gs - 1
.Rows("1:29").Copy .Cells(m, 1)
m = m + 29
Next i
m = 5
For i = 1 To n Step 15
xh = m - 1
.Cells(m - 1, 2) = bj
For s = i To i + 14
If s <= n Then
xh = xh + 1
For j = 1 To 4
.Cells(xh, j + 1) = arr(s, j)
Next j
For j = 6 To 10
.Cells(xh, j) = bz
Next j
.Cells(xh, 11) = bz * 5
End If
Next s
m = m + 29
Next i
End If
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|