mp.*_*peg 1 excel vba excel-vba
我正在尝试创建一个宏,一旦点击一个按钮就会显示一个输入框,只是说"你想要什么叫新表?",然后一旦用户输入了名称,Excel就会创建一个新的表单名称.
但是,我希望将原始工作表中的数据复制到用户已命名的新工作表中.
我有输入框工作,使用此代码:
Sub NewSheet()
Sheets.Add.Name = InputBox("What Would You Like to Call the New Sheet?")
End Sub
Run Code Online (Sandbox Code Playgroud)
请尝试以下代码:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1088 次 |
最近记录: |