Corrie Byrd
Corrie Byrd

Reputation: 29

Keep getting error copying sheet into another worksheet

Copy function error. Wanting to copy the sheet over to a created sheet with the date indicated. What is going on?

    Dim Dateini As String
    Dateini = "2021-03-31"
    Sheets("Sheet3").Copy After:=ActiveWorkbook.Sheets(Worksheets.Count).Name = Dateini

Upvotes: 1

Views: 490

Answers (1)

VBasic2008
VBasic2008

Reputation: 54777

Copy a Sheet

Option Explicit

Sub test()
    Const Dateini As String = "2021-03-31"
    ' Use 'ThisWorkbook' if it is the workbook containing this code.
    With ActiveWorkbook
        .Sheets("Sheet3").Copy After:=.Sheets(.Sheets.Count)
        .ActiveSheet.Name = Dateini
    End With
End Sub

Upvotes: 1

Related Questions