If you are a beginner in working with VBA macro in Excel 2013 and not getting along the best and ask ourselves how to copy VBA macro with some sites in your Excel 2013 and besides add a button on the worksheet to be copied VBA macro to run, then read this tutorial.
How to run the VB editor in Excel
Opening (Visual Basic Editor - Microsoft Visual Basic for Application) you can do the following ways
Clicking the Visual Basic command on the Developer toolbar.
Right-click on the name of the worksheet in the workbook (above the status bar) and the shortcut menu, choose the command 'View Code'.
Another way to open the VB editor in Excel by pressing ALT+F11 key combination on the keyboard.
How to copy the code VBA macros from some sites in your Excel
If you are on the Internet found VBA code that suits your needs and the considering how and the where you need to copy the code VBA macro here's a quick guide.
The first step, open a web page where there is a VBA macro code. So, you've read the instructions on the website and the how it works VBA macro in which modules you need to copy (this is important).
Start your Excel 2013
Open the VBE (Visual Basic Editor - Microsoft Visual Basic for Application) by clicking the command Visual Basic on the Developer toolbar (if you do not have an active Developer toolbar, then look at the link, How to display the Developer toolbar on the Ribbon).
You opened the VB editor in the right part of the working window 'Code Pane', you need to paste the code from the website. But here you need to be careful because there is a question where you need to paste the VBA code.
There are several modules ('Sheet Module', 'ThisWorkbook Module', 'Module?' and 'Class Module'). In as much as it comes Module1 and Module2 and you do not have it created in the workbook, then you need to add Module.
How to add a Module in VBE Workbook Excel
To add or create a Module in the VBE to Excel, you need to select the workbook in which you add Module (remember this, that the would not have happened to add Module into the wrong workbook when you have multiple open workbooks).
With the Text menu select group commands from the Insert menu and then select the Module command.
If this is the first Module to add then you notice that the created folder Modules which are placed modules to add.
When you add a Module or if it is desirable Sheet modules (see another way of opening described above) you then please select it in the left side of the working window VBE. In the right part of the window in the VBE working 'Code Pane' paste the copied VBA code. Carefully look copied VBA macro code. Should not be any red letters or pieces of code because it means that there is an error in this part of the command. Click the Save As command that the save the changes but so that the file type, select the type 'Excel Macro - Enabled Workbook'. You are ready to create or add a button to the worksheet and run VBA macro using the button.
How to run a VBA macro using a button in Excel
After a successful copy VBA code in VBE to Excel if you want you can add a button by which you can run a VBA macro.
In the following items you look at all the ways you can run a VBA macro in Excel.
- Use the shortcut ALT+F8 key combination on your keyboard
- Using Macros command on the Developer toolbar
- Use the View Macros command in the Macros group on the VIEW toolbar.
- Use the buttons that connect from VBA macro
- We are now interested in connecting buttons and VBA macro.
How to to insert a button on the worksheet to run VBA macros in Excel
The situation is that we end up copying the VBA macro code in the VBE to Excel. Position on some sheet (depends on what works VBA macro). Take for example that we want to run a VBA macro from Sheet1. So active is Sheet1. Click on the Developer toolbar and then on the Insert command and the choose the first icon Button command (Form Control).
In the next step, you need by utilizing the drag-and-drop to create a button on the Excel worksheet. So, click on the worksheet left mouse button and the hold it. Drag a selection rectangle to any size and the release the left mouse button.
The next step opens a dialog window 'Assign Macro' where you need to select the VBA macro from the list. In this example, I have just one VBA macro listed. After selecting VBA macro, click on OK button.
After clicking the OK button, we have the following situation (see image below). Click on the button and you notice that the VBA macro is executed procedure.
Also! You can record VBA macro in Excel.