Excelmacros给input框,创build新工作表,从原始表复制数据到新工作表

我试图创build一个macros,一旦点击一个button就会显示一个input框,只是简单地说“你想叫什么新的工作表?”,然后一旦用户input了名字,Excel就会创build一个新的工作表名称。

但是,我希望将原始表单中的数据复制到用户指定的新表单中。

我有input框工作,与此代码:

Sub NewSheet() Sheets.Add.Name = InputBox("What Would You Like to Call the New Sheet?") End Sub 

试试下面的代码:

  Sub NewSheet() Dim origSht As Worksheet Dim destSht As Worksheet On Error GoTo eHandle Set origSht = ActiveSheet Sheets.Add.Name = InputBox("What Would You Like to Call the New Sheet?") Set destSht = ActiveSheet origSht.Cells.Copy Destination:=destSht.Cells Exit Sub eHandle: MsgBox "You must name the new sheet" set origSht = nothing set destSht = nothing End Sub