我需要使用vba中的inputbox在excel中填充数学表。 “如何在新添加的表格中填充表格?”

时间:2013-03-11 06:56:47

标签: excel-vba vba excel

我正在使用以下代码,

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

1 个答案:

答案 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