|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
Function DelectDate()
on error resume Next
Dim oExcel,oWb,oSheet,count,RowsCount,name,t,s,i
count=0
t=0
Set oExcel= CreateObject("Excel.Application")
Set oWb = oExcel.Workbooks.Open("C:\2.xls")
\'设置第一个sheet为当前Excel的活动表格
Set oSheet = oWb.Sheets(1)
\'获取当前Excel表格总共多少行
RowsCount=oSheet.UsedRange.Rows.Count
for i=2 to RowsCount
name =oSheet.range("B"&i).Value
if (left(name,2)<>"杨航" and name<>"818978") Then
oSheet.range("A"&i).Value=i-1
count=count+1
else
t=t+1
oExcel.ActiveSheet.Rows(i).Delete
i=i-1
end If
If (i+t)=RowsCount Then
msgbox "您好!经过筛选,最终Excel符合要求的数量是:"&count
\'避免excel自动保存时弹出提示框 resume.xlw 文档是否覆蓋?
oExcel.DisplayAlerts = False
\'Excel自动保存
oExcel.Save()
oExcel.Quit
End If
next
End Function
|