|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- '打开工作表生成不重复值下拉
- Private Sub Worksheet_Activate()
- Dim arr, d As Object
- Set d = CreateObject("scripting.dictionary")
- r = Range("a65536").End(xlUp).Row
- arr = Range("a2:a" & r)
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = ""
- Next
- With Range("j1").Validation
- .Delete
- .Add 3, 1, 1, Join(d.keys, ",")
- End With
- End Sub
- '下拉选取管理部门进行单项打印
- Private Sub Worksheet_Change(ByVal Target As Range) '下拉或单元格值变化事件
- If Target.Address = "$J$1" Then
- If ActiveSheet.FilterMode = True Then ActiveSheet.ShowAllData
- Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:=Range("j1")
- ActiveWindow.SelectedSheets.PrintPreview '先打印预览(测试时启用/停用下一句)
- 'ActiveWindow.SelectedSheets.PrintOut '后打印当前表(测试通过正式打印时启用/停用上一句)
- End If
- End Sub
- '点击连续打印打印所有管理部门
- Private Sub CommandButton1_Click()
- Dim r%, i%
- Dim arr, k, s
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- r = Range("a65536").End(xlUp).Row
- arr = Range("a2:a" & r)
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = ""
- Next
- For i = 1 To d.Count
- If ActiveSheet.FilterMode = True Then ActiveSheet.ShowAllData
- Range("A1").CurrentRegion.AutoFilter Field:=1, Criteria1:=Application.Index(d.keys, 0, i)
- ActiveWindow.SelectedSheets.PrintPreview '先打印预览(测试时启用/停用下一句)
- 'ActiveWindow.SelectedSheets.PrintOut '后打印当前表(测试通过正式打印时启用/停用上一句)
- Next
- End Sub
- '取消筛选
- Private Sub CommandButton2_Click()
- ActiveSheet.ShowAllData
- End Sub
复制代码 |
|