|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 按钮5_Click()
- Dim myPath$, myName$, Arr1, i&, hb$, rq, Arr, n&, d
- Dim rng As Range, Myr&
- Set d = CreateObject("Scripting.Dictionary")
- Set rng = Selection
- If rng.Count > 1 Then Exit Sub
- If rng = "" Then Exit Sub
- If Intersect([b2:h32], rng) Is Nothing Then Exit Sub
- Myr = Sheet3.Cells(Sheet3.Rows.Count, 2).End(xlUp).Row
- Arr = Sheet3.Range("a5:c" & Myr)
- For i = 1 To UBound(Arr)
- x = Arr(i, 2) & "|" & Format(Arr(i, 3), "yyyy/m/d")
- d(x) = ""
- Next
- myPath = ThisWorkbook.Path & "" & Cells(rng.Row, 1).Value & ""
- myName = rng.Value & ".xls": n = Myr
- With GetObject(myPath & myName)
- Arr1 = .Sheets(1).UsedRange
- Arr = .Sheets(1).[a1].Resize(UBound(Arr1), 7)
- hb = Arr1(3, 2): rq = Arr1(3, 6)
- If Not d.exists(hb & "|" & rq) Then
- For i = 7 To UBound(Arr1)
- If InStr(Arr1(i, 1), "TOTAL") = 0 And InStr(Arr1(i, 1), "Mail") = 0 Then
- n = n + 1
- Sheet3.Cells(n, 2) = hb: Sheet3.Cells(n, 3) = rq
- Sheet3.Cells(n, 6).Resize(1, UBound(Arr, 2)) = Application.Index(Arr, i, 0)
- End If
- Next
- Else
- MsgBox "数据已经存在。"
- End If
- End With
- End Sub
复制代码 |
|