我的代码工作正常。但我试图解决输出如何自动插入名为“结果”的新工作表。有谁知道如何处理我的问题?
Sub macronew()
Dim NumberOfCompany As Integer
Dim column As Integer
Dim year As Integer
Do
year = 2004
For column = 20 To 22
For NumberOfCompany = 1 To 10
Range("N2").Activate
ActiveCell = year
Range("N3") = NumberOfCompany
SolverSolve UserFinish:=True
If SolverSolve(UserFinish:=True) = 4 Or SolverSolve(UserFinish:=True) = 5 Then
Cells(NumberOfCompany + 1, column) = "N/A"
Else
Range("L3").Select
Selection.Copy
Cells(NumberOfCompany + 1, column).Select
Selection.PasteSpecial Paste:=xlPasteValues
End If
Next NumberOfCompany
year = year + 1
Next column
Loop Until year > 2006
End Sub
答案 0 :(得分:0)
如果我正确理解您的问题,您需要创建新工作表并在新工作表中执行该代码。
如果是这种情况,请尝试在脚本开头添加以下代码段
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add(After:= ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ws.Name = "results"
sheets("results").activate