出于某种原因,Sheets.copy
正在制作另一本工作簿。我不知道如何解决它。我只是希望它复制第一个Sheets("New")
并将我选择的所有内容粘贴到新的Sheets("New(2)")
。
Sheets.Copy
Sheets("New").Select
Sheets("New").Copy After:=Sheet1
'****Copy Assessment Date to the Nourish Report Printable****
Sheets("New").Select
Range("C74").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("New (2)").Select
Range("V96").Select
ActiveSheet.Paste
答案 0 :(得分:0)
我认为问题出在Sheets
对象上。根据我的经验,最好使用Worksheets
对象。我建议通过删除所有复制和粘贴/选择来简化代码,只需使单元格范围采用您想要的精确值即可。宏记录器在生成高效代码方面做得不是很好,但它确实有助于语法并帮助您入门。请考虑以下代码来完成您想要的任务。
Sub CopySheet()
Dim wb As Workbook, ws As Worksheet, nws As Worksheet
'set up
Set wb = ThisWorkbook
Set ws = wb.Worksheets("New")
'Create a copy of the worksheet
ws.Copy wb.Worksheets(1) 'places the worksheet at the front
Set nws = wb.Worksheets(1) 'References the new front worksheet
'set a name for the new sheet for easy reference
nws.Name = "newSheet" 'set to whatever name you want
'Print out the actual value you want rather than copy and paste.
nws.Range("V96").Value = ws.Range("C74").Value
nws.Activate 'select the new worksheet
End Sub
这里没有所有评论
Sub CopySheet()
Dim wb As Workbook, ws As Worksheet, nws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("New")
ws.Copy wb.Worksheets(1)
Set nws = wb.Worksheets(1)
nws.Name = "newSheet"
nws.Range("V96").Value = ws.Range("C74").Value
End Sub
让我知道这是否有效。