大神们求教一下,这个拆分表,最后一页不能拆分显示全,怎么调代码比较好
本帖最后由 qwsss31 于 2020-9-23 10:56 编辑大神们求教一下,这个拆分表,最后一页不能拆分显示全,怎么调代码比较好。
不论多少页,拆分的最后一页总是缺少。
Sub AutoXXPage()
Dim sht As Worksheet
Dim shtT As Worksheet
Set sht = Worksheets("Sheet1")
Dim HP As HPageBreak
Dim strSRow As Long, strERow As Long
Dim n As Long
strSRow = "1"
For Each HP In sht.HPageBreaks
strERow = CStr(HP.Location.Row - 1)
n = n + 1
Set shtT = ThisWorkbook.Worksheets.Add
shtT.Name = "第" & CStr(n) & "页"
sht.Range(strSRow & ":" & strERow).Copy
shtT.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
strSRow = CStr(HP.Location.Row)
Next
n = n + 1
Set shtT = ThisWorkbook.Worksheets.Add
shtT.Name = "第" & CStr(n) & "页"
sht.Range(strSRow & ":" & CStr(sht.Range("g65536").End(xlUp).Row)).Copy
shtT.Paste
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
sht.Activate
Set sht = Nothing
Set shtT = Nothing
End Sub
VBA?
页:
[1]