|
- Sub THS导入导出()
- Application.DisplayAlerts = False
- With Workbooks.Open(Filename:=ThisWorkbook.Path & "\1结账数据源.xls", AddToMru:=True)
- .Sheets(1).Columns("A:H").Copy ThisWorkbook.Sheets(1).Columns("B:I")
- .Close
- End With
- ThisWorkbook.Activate
- Application.DisplayAlerts = True
- Dim arr, brr, d, i&, j%
- Set d = CreateObject("scripting.dictionary")
- str1 = "代码,名称,1部门金额(元)2019.11.29,2部门金额(元)2019.11.29,比(%)2019.11.29,结账时间2019.11.29,离开时间2019.11.30连续(天)2019.11.29"
- With CreateObject("vbscript.regexp")
- .Global = True
- .Pattern = "\d{4}\.\d{2}\.\d{2}"
- For Each mh In .Execute(str1)
- d(mh.Value) = 1 + d(mh.Value)
- Next mh
-
-
- End With
- str1 = Replace(str1, d.keys()(1), Format(Date + 1, "yyyy.mm.dd"))
- str1 = Replace(str1, d.keys()(0), Format(Date, "yyyy.mm.dd"))
- d.RemoveAll
- w = Split(str1, ",")
- arr = Sheet1.Range("a1").CurrentRegion
- ReDim brr(1 To UBound(arr), 1 To UBound(w) + 1)
- For i = 0 To UBound(w)
- d(w(i)) = i + 1
- Next
- For j = 1 To UBound(arr, 2)
- If d.exists(arr(1, j)) Then
- n = d(arr(1, j))
- For i = 1 To UBound(arr)
- brr(i, n) = arr(i, j)
- Next
- End If
- Next
- Sheet2.Activate
- Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End Sub
复制代码
重新看了下,之前的理解有误,这次看看吧 |
|