|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub NewSheets()
Dim d As Object, sht As Worksheet, arr, brr, r, kr, i&, j&, k&, x&
Dim Rng As Range, Rg As Range, tRow&, tCol&, aCol&, pd&
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("scripting.dictionary")
Set Rg = Application.InputBox("请您框选拆分依据列!只能选择单列单元格区域!", Title:="提示", Type:=8)
tCol = Rg.Column
tRow = Val(Application.InputBox("请您输入总表标题行的行数?"))
If tRow = 0 Then MsgBox "您未输入标题行行数,程序退出!": Exit Sub
Set Rng = ActiveSheet.UsedRange
arr = Rng
tCol = tCol - Rng.Column + 1
aCol = UBound(arr, 2)
For i = tRow + 1 To UBound(arr)
If Not d.exists(arr(i, tCol)) Then
d(arr(i, tCol)) = i
Else
d(arr(i, tCol)) = d(arr(i, tCol)) & "," & i
End If
Next
For Each sht In Worksheets
If d.exists(sht.Name) Then sht.Delete
Next
kr = d.keys
For i = 0 To UBound(kr)
If kr(i) <> "" Then
r = Split(d(kr(i)), ",")
ReDim brr(1 To UBound(r) + 1, 1 To aCol)
k = 0
For x = 0 To UBound(r)
k = k + 1
For j = 1 To aCol
brr(k, j) = arr(r(x), j)
Next
Next
With Worksheets.Add(, Sheets(Sheets.Count))
.Name = kr(i)
.[a1].Resize(tRow, aCol) = arr
.[a1].Offset(tRow, 0).Resize(k, aCol) = brr
Rng.Copy
.[a1].PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.[a1].Select
End With
End If
Next
Sheets(1).Activate
Set d = Nothing
Erase arr: Erase brr
MsgBox "数据拆分完成!"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
这是我从网上搜索来的代码,成功的拆分一个工作表为多个工作簿,但是我的表格里有年月日时分秒的日期被全部改成了数字,请问这要怎么办?不能改动它,是需要在这个代码里添加什么吗?求大神帮我检查一下,谢谢。
以下是我日期变动成数字的截图。
原数据
|
-
拆分后数据
|