|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
是否要這樣?
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim rng As Range, i&
- Set ic = Application.Intersect(Target, [a2:e2])
- If ic Is Nothing Then End
- Application.ScreenUpdating = 0
- Application.EnableEvents = 0
- i = [a1048576].End(3).Row
- If i > 2 Then Rows("3:" & i).Delete
- [a2:b2].NumberFormat = "@"
- With Sheets(1)
- .[a1].CurrentRegion.AutoFilter Field:=ic.Column, Criteria1:=ic.Value
- .[a1].CurrentRegion.Copy
- [a1].Activate
- ActiveSheet.Paste
- .AutoFilterMode = 0
- End With
- Sheets(3).[a1:f1].Copy [a1048576].End(3)(2)
- Application.EnableEvents = 1
- Application.ScreenUpdating = 1
- End Sub
复制代码
- Sub zz()
- Dim d As Object, i&
- Application.EnableEvents = 0
- Set d = CreateObject("scripting.dictionary")
- i = [a1048576].End(3).Row
- If i > 2 Then Rows("3:" & i).Delete
- [a2:f2] = ""
- With Sheets(1)
- ar = .[a1].CurrentRegion.Value
- For j = 1 To UBound(ar, 2) - 1
- For i = 2 To UBound(ar)
- d(ar(i, j)) = ""
- Next
- Cells(2, j).Validation.Delete
- Cells(2, j).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
- xlBetween, Formula1:=Join(d.keys, ",")
- d.RemoveAll
- Next
- End With
- Set d = Nothing
- MsgBox "Validation updated, please choice from [a2:e2]"
- Application.EnableEvents = 1
- End Sub
复制代码 |
|