|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim Dic As Object, wB As Workbook, Arr, sH As Worksheet, mFile$, mPath$
- Dim i&, j&, hS&
- Set Dic = CreateObject("scripting.dictionary")
- Set sH = ActiveSheet
- With sH
- mrow = .Cells(.Rows.Count, "A").End(3).Row
- Arr = .[a1].Resize(mrow, 9)
- End With
- For i = 2 To UBound(Arr, 1)
- If Arr(i, 1) <> "" Then
- If Dic.exists(Arr(i, 1)) Then Dic(Arr(i, 1)) = Dic(Arr(i, 1)) & Chr(10) & i Else Dic(Arr(i, 1)) = i
- End If
- Next i
- mPath = ThisWorkbook.Path
- For Each d In Dic.keys
- mFile = mPath & "" & d & ".xlsx"
- If Dir(mFile) <> "" Then Kill mFile
- Set wB = Workbooks.Add
- Set sH = wB.Worksheets(1)
- With sH
- Trr = Split(Dic(d), Chr(10))
- ReDim brr(1 To UBound(Trr) + 2, 1 To UBound(Arr, 2) - 1)
- For j = 2 To UBound(Arr, 2)
- brr(1, j - 1) = Arr(1, j)
- Next j
- For i = 0 To UBound(Trr)
- hS = Val(Trr(i))
- For j = 2 To UBound(Arr, 2)
- brr(i + 2, j - 1) = Arr(hS, j)
- Next j
- Next i
- .[a1].Resize(UBound(brr, 1), UBound(brr, 2) - 1).NumberFormat = "@"
- .[h2].Resize(UBound(brr, 1), 1).NumberFormatLocal = "yyyy-mm-dd"
- .[a1].Resize(UBound(brr, 1), UBound(brr, 2)) = brr
- .UsedRange.EntireColumn.AutoFit
- End With
- wB.SaveAs mFile, 51
- wB.Close 0
- Next d
- End Sub
复制代码 |
|