|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$2" Then
Dim arr As Variant, i
Dim brr(), crr()
arr = Sheet3.Range("a1").CurrentRegion
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
ReDim crr(1 To UBound(arr), 1 To 17)
s = Sheet1.[c2].Value
For i = 2 To UBound(arr)
If arr(i, 10) = s Then
m = m + 1
For c = 2 To UBound(arr, 2)
brr(m, c) = arr(i, c)
Next
brr(m, 1) = m
crr(m, 1) = m
crr(m, 2) = arr(i, 2)
crr(m, 3) = arr(i, 3)
crr(m, 5) = arr(i, 4)
crr(m, 10) = arr(i, 10)
crr(m, 11) = arr(i, 11)
For j = 5 To 9
crr(m, j + 8) = arr(i, j)
Next j
End If
Next
If m = "" Then MsgBox "没有所选部门的数据!": End
r = Cells(Rows.Count, 1).End(xlUp).Row
If r > 3 Then Range("a4:m" & r).Borders.LineStyle = 0: Range("a4:m" & r) = Empty
Range("a4").Resize(m, UBound(brr, 2)) = brr
Range("a4").Resize(m, UBound(brr, 2) + 2).Borders.LineStyle = 1
With Sheets("更正底稿")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If r > 1 Then .Range("a2:r" & r).Borders.LineStyle = 0: .Range("a2:r" & r) = Empty
.Range("a2").Resize(m, UBound(crr, 2)) = crr
.Range("a2").Resize(m, UBound(crr, 2) + 1).Borders.LineStyle = 1
End With
End If
End Sub
|
|