简体   繁体   中英

Invalid Outside Procedure for range.copy function

I am brand new to VBA Excel coding and I am trying to perform a simple range.copy function to automate copying and pasting values from one worksheet to another. The following is my code:

Private Sub CommandButton1_Click()

 Worksheets("Consolidated YTD").Range("A1:AF144").copy Worksheets("Consolidated PriorYTD").Range("A1")

I keep getting a compile error for invalid outside procedure. Does anyone have any idea as to why this is the case? Thanks!

You must close your sub adding End Sub:

Private Sub CommandButton1_Click()
 Worksheets("Consolidated YTD").Range("A1:AF144").copy Worksheets("Consolidated PriorYTD").Range("A1")
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM