|
楼主 |
发表于 2018-9-3 08:58
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我那个文件涉及好多不能公开的东西(请谅解),用下面已经很成熟的代码你自己研究一下(“退绩”是当前工作表名、 st = Sheets("说明").[K6].Value是要筛选的引用单元格):
Private Sub Worksheet_Activate()
ActiveSheet.Unprotect Password:="333"
ActiveWorkbook.Worksheets("退绩").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("退绩").Sort.SortFields.Add Key:=Range("C7:C350"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("退绩").Sort.SortFields.Add Key:=Range("G7:G350"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("退绩").Sort.SortFields.Add Key:=Range("E7:E350"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("退绩").Sort
.SetRange Range("C7:J350")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
st = Sheets("说明").[K6].Value
ActiveSheet.Range("m8:m" & Cells(Rows.Count, 3).End(3).Row).AutoFilter Field:=1, Criteria1:=st, _
Operator:=xlOr, Criteria2:="=1"
Range("A7:A17").Select
ActiveSheet.Protect Password:="333"
End Sub
|
|