filmov
tv
How to make a button, and assign a macro to it in Excel - full tutorial!

Показать описание
#excel #exceltips #exceltutorial #exceltricks #exceltipsandtricks
Follow me on other media:
Music used:
Annotations:
First, make sure the developer tab is enabled.
If it's not, enable it:
Right-click the ribbon, and click 'Customize the Ribbon...'.
Click the checkbox in front of 'Developer', and click 'OK'.
The Developer tab is now available.
On this tab, Click Insert, and click on the Button [Form Control].
Now click the location on the sheet where you want to insert the button.
Enter a Name for your Macro.
Click 'Record...' to record a Macro. Click 'OK'.
You're now recording a Macro. Every action you perform in Excel while recording will automatically be written out in VBA code for you.
I want a click on my button to hide column F.
I now manually select and hide column F.
This is all I want this macro to do, so I can stop recording now.
Press the stop button in the bottom left on the screen to stop recording.
Testing the macro...
It works!
Editing the button and macro
I made another button that unhides column F.
However, during the recording of the macro I selected E:G and then clicked 'unhide' to unhide F.
I want to edit the macro to only select column F.
Right-click the button, click Assign Macro, select the macro you want to edit, and click 'Edit'.
This will take you to the recorded VBA code.
Module1 shows the VBA code for both macro's I recorded.
I want to edit the second macro called 'UnHideF'.
The macro states it selects column E:G, which I edit to F:F.
Make your edits, and close the VBA screen to return to Excel.
It now only selects column F. It works!
To edit the text on your button, right-click the button and click 'Edit Text'
Type the text and press Enter.
An Excel sheet that contains macros has to be saved as a '.xlsm' rather than the standard '.xlsx' for the macro's to function.
Select the '.xlsm' filetype and click 'save'.
In the next video in this series I'll show how to add multiple functions to one button.
Комментарии