简体   繁体   中英

Excel - copy cells+macro+VBA from one sheet to another?

I'm trying to modify my spreadsheet so that when you click on the "insert worksheet" button, it adds the text, forms, VBA, Macro, etc from cells B38-K38:B52-K52 to a new worksheet and allows the user to click on the "Click Here" button I have and enter the data as desired. I tried doing this with a VBA script but it is coming up with an error because everytime it adds a sheet, the number will go up. Will incrementing fix this or is there another solution?

Edit, here's the solution:

Sub new_sheet()
    '
    ' new_sheet Macro
    ' Copies the range of B36:L52 (Problems Identified) to a new sheet
    ' Then resizes columns
    ' Keyboard Shortcut: Ctrl+q
    Worksheets.Add after:=Worksheets(Worksheets.Count), Count:=1
    Worksheets("Sheet1").Range("B36:L52").Copy Destination:=ActiveSheet.Range("A1")
    Cells.Select
    Selection.Columns.AutoFit
End Sub

A simple macro like this:

ActiveSheet.Copy after:=ActiveSheet
ActiveSheet.Name = "NewSheet"

Will copy the active sheet and everything in it, and make a new one that is called "NewSheet". Would that help?

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