我有一个宏,可以通过数据并按特定格式将其输出到另一个工作表。问题是,在填充了第65,536行后,它会出现错误,我猜这是微软设定的限制:
Sub Macro1()
'
' Macro1 Macro
'
'
Sheets.Add.Name = "Sheet2"
Worksheets("Sheet2").Cells(1, 1).Value = "datacol1"
Worksheets("Sheet2").Cells(1, 2).Value = "datacol2"
Worksheets("Sheet2").Cells(1, 3).Value = "datacol3"
Worksheets("data").Activate
SourceColumn = 2
SourceRow = 2
Cells(SourceRow, 1).Activate
targetRow = SourceRow
targetcolumn = 1
While Cells(1, SourceColumn).Value <> ""
While ActiveCell.Value <> ""
Worksheets("Sheet2").Cells(targetRow, targetcolumn).Value = ActiveCell.Value
Worksheets("Sheet2").Cells(targetRow, targetcolumn + 1).Value = Worksheets("Data").Cells(1, SourceColumn).Value
Worksheets("Sheet2").Cells(targetRow, targetcolumn + 2).Value = Worksheets("Data").Cells(SourceRow, SourceColumn).Value
SourceRow = SourceRow + 1
targetcolumn = 1
targetRow = targetRow + 1
Cells(SourceRow, 1).Activate
Wend
SourceColumn = SourceColumn + 1
SourceRow = 2
Cells(SourceRow, 1).Activate
Wend
With Worksheets("Sheet2").Sort
.SetRange Range(Cells(2, 1), Cells(targetRow, 3))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
我该在这个宏中添加什么,以便当它达到65,536的限制时,创建一个新的工作表并继续执行?