excel 如何将带有代码工作表复制到同一工作簿中

xxhby3vn  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(142)

我添加了一个按钮来复制活动工作表并添加到活动工作簿的末尾,这工作正常,但它不复制活动工作表VBA代码。

Sub CopySheet()
'When button is press on the NEW sheet copies active worksheet to end of active workbook 
If ActiveSheet.Name Like "NEW**" Then
ActiveSheet.Copy Before:=Worksheets(Sheets.Count)
On Error Resume Next
End If
End Sub

复制工作表时要复制到的代码。

Private Sub Worksheet_Change(ByVal Target As Range)
'if PO number is updated the Active NEW sheet date is update to today's date.
If Not Intersect(Target, Range("d5")) Is Nothing Then
    Range("a8").Value = Now()
End If
End Sub

不复制Excel工作表上的VBA代码

ac1kyiln

ac1kyiln1#

有条件复制工作表为最后一张工作表

Sub CopySheet()
    
    If ActiveSheet Is Nothing Then Exit Sub ' no visible workbooks open
    
    With ActiveSheet
        If .Name Like "NEW*" Then ' begins with "NEW" - case sensitive
           .Copy After:=.Parent.Sheets(.Parent.Sheets.Count) ' after last sheet
        End If
    End With
    
End Sub

相关问题