0% found this document useful (0 votes)
15 views

Adding Buttons To The Worksheet

This document provides instructions for adding buttons to a worksheet in Excel that run macros. It describes how to insert buttons, copy and paste macro code into the Visual Basic Editor (VBE) to create workbook and button event macros, and assign the button macro to the worksheet buttons. The button macro is provided that will activate the last worksheet selected when the button is clicked.

Uploaded by

Raymond Yong
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Adding Buttons To The Worksheet

This document provides instructions for adding buttons to a worksheet in Excel that run macros. It describes how to insert buttons, copy and paste macro code into the Visual Basic Editor (VBE) to create workbook and button event macros, and assign the button macro to the worksheet buttons. The button macro is provided that will activate the last worksheet selected when the button is clicked.

Uploaded by

Raymond Yong
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Adding Buttons to the Worksheet 1. Click View on the Excel Menu Bar or use ALT+V. 2.

Click Toolbars or type T to display the available toolbars. 3. Click on Forms or use the Down Arrow to select this toolbar. 4. Look for the rectangular icon. When you place the mouse on it you will see Button displayed. 5. Click on this icon. 6. Move the cursor to the cell where you want the button. Left Click and Hold the button down while you move the mouse. This will draw the button. Release the button when you are done. 7. A dialog box will appear asking you to assign a macro. Close the dialog. You can add the macro later. 8. Repeat steps from 4 on to add more buttons. How to Save a Workbook Event Macro 1. Copy the macro using CTRL+C keys. 2. Open your Workbook and Right Click on any Worksheet's Name Tab 3. Left Click on View Code in the pop up menu. 4. Press ALT+F11 keys to open the Visual Basic Editor. 5. Press CTRL+R keys to shift the focus to the Project Explorer Window 6. Press the Down Arrow Key until ThisWorkbook is highlighted in blue. 7. Press the Enter key to move the cursor to the Code Window 8. Paste the macro code using CTRL+V 9. Save the macro in your Workbook using CTRL+S Workbook Event Macro Code Code:
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object) LastWorksheet = Sh.Name End Sub

Button Macro Code Copy this into a standard VBA module. Code:
Public LastWorksheet As String Sub PreviousSheet() If LastWorksheet <> "" Then Worksheets(LastWorksheet).Activate Else MsgBox "No other Sheet has been selected." End If End Sub

Adding the Macro 1. Copy the macro above pressing the keys CTRL+C 2. Open your workbook 3. Press the keys ALT+F11 to open the Visual Basic Editor 4. Press the keys ALT+I to activate the Insert menu 5. Press M to insert a Standard Module 6. Paste the code by pressing the keys CTRL+V 7. Make any custom changes to the macro if needed at this time. 8. Save the Macro by pressing the keys CTRL+S 9. Press the keys ALT+Q to exit the Editor, and return to Excel. Assign the Macro to your Button 1. Right Click the Button 2. Select Assign Macro... 3. A dialog box will appear with the available macros. 4. Select PreviousSheet 5. Click Ok

You might also like