How to create a Command Button to copy and paste data in Excel?
Supposing you need to frequently copy a range of cells to other place after changing the data, the manually copy and paste method will be fussy and time-consuming. How to make this copy and paste affair running automatically? This article will show you how to use a command button to copy and paste data with only one click.
Excel Productivity Tools
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
Please do as follows to copy and paste data automatically when clicking a Command Button.
1. Insert a Command Button by clicking Developer > Insert > Command Button (ActiveX Control). See screenshot:
2. Draw a Command Button in your worksheet and right click it. Select View Code from the context menu.
3. In the popping up Microsoft Visual Basic for Applications window, please replace the original code in the Code window with below VBA code.
VBA code: Use Command Button to copy and paste data in Excel
Private Sub CommandButton1_Click() Application.ScreenUpdating = False Dim xSheet As Worksheet Set xSheet = ActiveSheet If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then xSheet.Range("A1:C17 ").Copy xSheet.Range("J1:L17").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False End If Application.ScreenUpdating = True End Sub
Note: In the code, CommandButton1 is the name of your inserted Command Button. A1:C17 is the range you need to copy, and J1:L17 is the destination range to paste data. Please change them as you need.
4. Press Alt + Q keys to close the Microsoft Visual Basic for Applications window. And turn off the Design Mode under the Developer tab.
5. Now click the Command Button, all data in range A1:C17 will be copied and pasted into range J1:L17 without the cell formatting.
- How to save and close active workbook without prompt by a Command Button in Excel?
- How to always floating a Command Button on worksheet in Excel?
- How to update or insert (current) date and time by a Command Button in Excel?
- How to use a Command Button to change a specified cell value in Excel?
- How to use Command Button to save active worksheet as PDF file in Excel?
- How to insert a blank new row automatically by Command Button in Excel?
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 28 days agoI'm looking for some help on that a user can click on a row number and then hit the command button that it will make a copy of that row and insert it into the row below it.
To post as a guest, your comment is unpublished.· 1 months agohi, help my case, i want have a button to generate macro where i have excel and export the data where in the <" "> to word, thanks
To post as a guest, your comment is unpublished.· 2 months agoHi Author,
The article you mentioned above is very helpful to me. I am not used to excel code and command. I still need to know rather than this article. I am ok with the copy and paste into next sheet. But I still need to know "how to paste and add into new line in next sheet every time I press the button". Otherwise, my data on next sheet will be replaced every time. I would really be grateful and looking forward to see your reply.
To post as a guest, your comment is unpublished.· 2 months agoI have a qusrion I have sheet 1 with a column of date b3:b33 and I want that to be copied to sheet 2 B33:b63 its text but I need the same format for text ie colour size
To post as a guest, your comment is unpublished.· 3 months agoIf I want to Copy this not in the current workbook but into another workbook (which is still not opened) in excel. How do I change this VBA code accordingly?