我正在使用以下代码,
Sub chk()
Dim x As Variant
Select Case StrPtr(x)
Case 0
Exit Sub
Case Else
Dim d As Integer
Dim y As Integer
Dim ws As Object
Set ws = Worksheets(1)
d = InputBox("enter the integer")
For y = 1 To 10
ws.Cells(y, 1) = y * d
Next y
ActiveSheet.Name = d
ActiveWorkbook.Sheets.Add after:=Worksheets(3)
Set ws = Nothing
End Select
End Sub
答案 0 :(得分:0)
在我看来,您的表总是被添加到Sheet1而不是您添加的新工作表?如果您希望将表添加到新工作表中,请执行以下操作:
Sub chk()
Dim x As Variant
Select Case StrPtr(x)
Case 0
Exit Sub
Case Else
Dim d As Integer
Dim y As Integer
Dim ws As Worksheet
d = InputBox("enter the integer")
Set ws = ActiveWorkbook.Sheets.Add After:=Worksheets(3)
ws.Name = d
For y = 1 To 10
ws.Cells(y, 1) = y * d
Next
Set ws = Nothing
End Select
End Sub