0
我需要将PT /原始(百万)数据分成多个工作表(基于员工数量约为1000)。我使用了附带的代码和示例文件,该宏符合我的要求。然而,现有的代码并不是自行创建工作表,但是我有1000名学生,所以我想通过代码创建尽可能多的工作表。由于我是VB新手,所以不确定要更改哪部分。我在线获取代码来创建工作表,但不知道如何将其插入原始文件。任何帮助都会有所帮助。下面是将原始数据分成已有多个工作表中的代码:如何将数据透视表/原始数据分成多个工作表
Sub copyPasteData()
Dim strSourceSheet As String
Dim strDestinationSheet As String
Dim lastRow As Long
strSourceSheet = "Data entry"
Sheets(strSourceSheet).Visible = True
Sheets(strSourceSheet).Select
Range("C2").Select
Do While ActiveCell.Value <> ""
strDestinationSheet = ActiveCell.Value
ActiveCell.Offset(0, -2).Resize(1, ActiveCell.CurrentRegion.Columns.Count).Select
Selection.Copy
Sheets(strDestinationSheet).Visible = True
Sheets(strDestinationSheet).Select
lastRow = LastRowInOneColumn("A")
Cells(lastRow + 1, 1).Select
Selection.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sheets(strSourceSheet).Select
ActiveCell.Offset(0, 2).Select
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Public Function LastRowInOneColumn(col)
Dim lastRow As Long
With ActiveSheet
lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
End With
LastRowInOneColumn = lastRow
End Function
下面
是创建多个工作表
Sub AddSheets()
Dim cell As Excel.Range
Dim wsWithSheetNames As Excel.Worksheet
Dim wbToAddSheetsTo As Excel.Workbook
Set wsWithSheetNames = ActiveSheet
Set wbToAddSheetsTo = ActiveWorkbook
For Each cell In wsWithSheetNames.Range("A2:A5")
With wbToAddSheetsTo
.Sheets.Add after:=.Sheets(.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = cell.Value
If Err.Number = 1004 Then
Debug.Print cell.Value & " already used as a sheet name"
End If
On Error GoTo 0
End With
Next cell
End Sub
'我有1000名学生,所以我想创建尽可能多的工作表的代码,因为有学生'很确定你不能有1000张XD – findwindow
@findwindow一个疯狂的想法,但[限制可用内存(默认为1张)](https://support.office.com/zh-cn/article/Excel-specifications-and-limits -ca36e2dc-1f09-4620-b726-67c00b05040f)。 – pnuts
@pnuts我猜如果每张纸只保存<10字节。我在i7上安装了16GB的RAM,30张正在爬我的盒子XD – findwindow