|
哪位大佬帮忙看一下[a1].Offset(tRow, 1).Resize(k, aCol) = brr 这个a1怎么改写a&n的方法让指定的单元成为可变性
这是网上借鉴的一个拆分表格的代码
完整代码
Sub 拆()
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&
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
Dim n
With Worksheets.Add(, Sheets(Sheets.Count))
.Name = kr(i)
.[a1].Resize(tRow, aCol) = arr
n = Range("c55555").End(xlUp).Row
MsgBox n
.["a"&n].Offset(tRow, 1).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
|
|